﻿using Autodesk.AutoCAD.Colors;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using FDEEPublicFunc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FDEEInterface
{
    public class PolylinePloter
    {
        public static void AddPolyline(Database db, ref Extents2d ext, Point2d sp, Point2d ep, double dx0, double dy0, double dx1, double dy1, string linetypeName, short num = 0,double lines=1)
        {
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                Polyline line = new Polyline() { Closed = false, Layer = linetypeName,LinetypeScale= lines };//定义不封闭的Polyline
                line.AddVertexAt(0, sp.Convert2D(dx0, dy0), 0, 0, 0);
                line.AddVertexAt(1, ep.Convert2D(dx1, dy1), 0, 0, 0);
                Color color = Color.FromColorIndex(ColorMethod.ByColor, num);

                line.Color = color;
                line.LineWeight = Autodesk.AutoCAD.DatabaseServices.LineWeight.ByLayer;

                recorder.AppendEntity(line);
                tr.AddNewlyCreatedDBObject(line, true);
                ext = ext.Add(new Extents2d(line.Bounds.Value.MinPoint.Convert2D(), line.Bounds.Value.MaxPoint.Convert2D()));

                tr.Commit();
            }
        }

        public static void AddPolylineByList(Database db, ref Extents2d ext, List<Point2d> ptList, string linetypeName, short num = 0,bool isClose=true)
        {
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                Polyline line = new Polyline() { Closed = isClose, Layer = linetypeName };//定义不封闭的Polyline
                for (int i = 0; i < ptList.Count; i++)
                {
                    line.AddVertexAt(0, ptList[i], 0, 0, 0);
                }
                Color color = Color.FromColorIndex(ColorMethod.ByColor, num);

                line.Color = color;
                line.LineWeight = Autodesk.AutoCAD.DatabaseServices.LineWeight.ByLayer;

                recorder.AppendEntity(line);
                tr.AddNewlyCreatedDBObject(line, true);
                ext = ext.Add(new Extents2d(line.Bounds.Value.MinPoint.Convert2D(), line.Bounds.Value.MaxPoint.Convert2D()));

                tr.Commit();
            }
        }
        public static void AddBJByDirectiong(Database db, ref Extents2d ext, Point3d insertPt, ArrowDirection arrDir,  string textstring = "A", double scale = 1)
        {
            double width = 1.5*scale;
            double height = 3 * scale;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                Polyline line = new Polyline() { Closed = false, Layer = "细线" };//定义不封闭的Polyline 平面虚线
                DBText txt = new DBText();
                txt.TextString = textstring.ToString();
                txt.Height = 2.5 * scale;             
                txt.HorizontalMode = TextHorizontalMode.TextCenter;
                txt.VerticalMode = TextVerticalMode.TextVerticalMid;
               
                txt.TextStyleId = st[Extensions.curFont];
                txt.Layer = "标注";
                txt.WidthFactor = 0.8;
                #region 箭头
                Solid Array = new Solid();
                Array.Layer = "标注";
                Point3d refpt;
                switch (arrDir)
                {  
                    case ArrowDirection.North:  //上
                        refpt = insertPt.Convert3D(width+2.65*scale, 0);                               
                            Array = new Solid(
                                 refpt.Convert3D(0 , 0, 0),
                                 refpt.Convert3D(-2.65 * scale, 0, 0),
                                  refpt.Convert3D(-2 * scale, 0.5 * scale, 0)
                                 )
                            { Color = Color.FromColorIndex(ColorMethod.ByAci, 7), };
                            modelSpace.AppendEntity(Array);
                            tr.AddNewlyCreatedDBObject(Array, true);

                        line.AddVertexAt(0, insertPt.Convert2D(width), 0, 0, 0);
                        line.AddVertexAt(1, insertPt.Convert2D(), 0, 0, 0);
                        line.AddVertexAt(2, insertPt.Convert2D(0, -height), 0, 0, 0);
                        modelSpace.AppendEntity(line);
                        tr.AddNewlyCreatedDBObject(line, true);

                        txt.Position = insertPt.Convert3D(1*scale, -1.5 * scale);
                        txt.AlignmentPoint = insertPt.Convert3D(1 * scale, -1.5 * scale);
                        break;
                    case ArrowDirection.South:  //下
                      
                        refpt = insertPt.Convert3D(width + 2.65 * scale, 0);
                        Array = new Solid(
                           refpt.Convert3D(0 , 0, 0),
                           refpt.Convert3D(-2.65 * scale , 0, 0),
                            refpt.Convert3D(-2 * scale , -0.5 * scale, 0)
                           )
                            { Color = Color.FromColorIndex(ColorMethod.ByAci, 7), };

                            modelSpace.AppendEntity(Array);
                            tr.AddNewlyCreatedDBObject(Array, true);
                        line.AddVertexAt(0, insertPt.Convert2D(width), 0, 0, 0);
                        line.AddVertexAt(1, insertPt.Convert2D(), 0, 0, 0);
                        line.AddVertexAt(2, insertPt.Convert2D(0, height), 0, 0, 0);
                        modelSpace.AppendEntity(line);
                        tr.AddNewlyCreatedDBObject(line, true);

                        txt.Position = insertPt.Convert3D(1 * scale, 1.5 * scale);
                        txt.AlignmentPoint = insertPt.Convert3D(1 * scale, 1.5 * scale);
                        break;
                    case ArrowDirection.West:  //左
                        width = 3 * scale;
                        height = 1.5 * scale;
                        refpt = insertPt.Convert3D(0, -height - 2.65 * scale);
                        Array = new Solid(
                            refpt.Convert3D(0, 0 , 0),
                            refpt.Convert3D(0, 2.65 * scale , 0),
                             refpt.Convert3D(-0.5 * scale, 2 * scale , 0)
                            )
                            { Color = Color.FromColorIndex(ColorMethod.ByAci, 7), };

                            modelSpace.AppendEntity(Array);
                            tr.AddNewlyCreatedDBObject(Array, true);

                        line.AddVertexAt(0, insertPt.Convert2D(width), 0, 0, 0);
                        line.AddVertexAt(1, insertPt.Convert2D(), 0, 0, 0);
                        line.AddVertexAt(2, insertPt.Convert2D(0, -height), 0, 0, 0);
                        modelSpace.AppendEntity(line);
                        tr.AddNewlyCreatedDBObject(line, true);

                        txt.Position = insertPt.Convert3D(1 * scale, -1.5 * scale);
                        txt.AlignmentPoint = insertPt.Convert3D(1 * scale, -1.5 * scale);
                        break;
                    case ArrowDirection.East:   //右
                        width = 3 * scale;
                        height = 1.5 * scale;
                        refpt = insertPt.Convert3D(0, -height- 2.65 * scale);
                        Array = new Solid(
                             refpt.Convert3D(0, 0 , 0),
                             refpt.Convert3D(0, 2.65 * scale , 0),
                              refpt.Convert3D(0.5 * scale, 2 * scale, 0)
                             )
                            { Color = Color.FromColorIndex(ColorMethod.ByAci, 7), };

                            modelSpace.AppendEntity(Array);
                            tr.AddNewlyCreatedDBObject(Array, true);
                        line.AddVertexAt(0, insertPt.Convert2D(-width), 0, 0, 0);
                        line.AddVertexAt(1, insertPt.Convert2D(), 0, 0, 0);
                        line.AddVertexAt(2, insertPt.Convert2D(0, -height), 0, 0, 0);
                        modelSpace.AppendEntity(line);
                        tr.AddNewlyCreatedDBObject(line, true);

                        txt.Position = insertPt.Convert3D(-1* scale, -1.5 * scale);
                        txt.AlignmentPoint = insertPt.Convert3D(-1 * scale, -1.5 * scale);
                        break;
                }
                ext = ext.Add(new Extents2d(Array.Bounds.Value.MinPoint.Convert2D(), Array.Bounds.Value.MaxPoint.Convert2D()));
                ext = ext.Add(new Extents2d(line.Bounds.Value.MinPoint.Convert2D(), line.Bounds.Value.MaxPoint.Convert2D()));
                #endregion

                #region
              
                modelSpace.AppendEntity(txt);
                tr.AddNewlyCreatedDBObject(txt, true);
                ext = ext.Add(new Extents2d(txt.Bounds.Value.MinPoint.Convert2D(), txt.Bounds.Value.MaxPoint.Convert2D()));
                #endregion
                tr.Commit();
                }
        }

        public static void AddL2RUpperBJByDirectiong(Database db, ref Extents2d ext, Point3d insertPt, ArrowDirection arrDir, string textstring = "A", double scale = 1)
        {
            double width = 1.5 * scale;
            double height = 3 * scale;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                Polyline line = new Polyline() { Closed = false, Layer = "细线" };//定义不封闭的Polyline 平面虚线
                DBText txt = new DBText();
                txt.TextString = textstring.ToString();
                txt.Height = 2.5 * scale;
                txt.HorizontalMode = TextHorizontalMode.TextCenter;
                txt.VerticalMode = TextVerticalMode.TextVerticalMid;

                txt.TextStyleId = st[Extensions.curFont];
                txt.Layer = "标注";
                txt.WidthFactor = 0.8;
                #region 箭头
                Solid Array = new Solid();
                Array.Layer = "标注";
                Point3d refpt;
                switch (arrDir)
                {
                    case ArrowDirection.North:  //上
                        refpt = insertPt.Convert3D(width + 2.65 * scale, 0);
                        Array = new Solid(
                             refpt.Convert3D(0, 0, 0),
                             refpt.Convert3D(-2.65 * scale, 0, 0),
                              refpt.Convert3D(-2 * scale, 0.5 * scale, 0)
                             )
                        { Color = Color.FromColorIndex(ColorMethod.ByAci, 7), };
                        modelSpace.AppendEntity(Array);
                        tr.AddNewlyCreatedDBObject(Array, true);

                        line.AddVertexAt(0, insertPt.Convert2D(width), 0, 0, 0);
                        line.AddVertexAt(1, insertPt.Convert2D(), 0, 0, 0);
                        line.AddVertexAt(2, insertPt.Convert2D(0, -height), 0, 0, 0);
                        modelSpace.AppendEntity(line);
                        tr.AddNewlyCreatedDBObject(line, true);

                        txt.Position = insertPt.Convert3D(1 * scale, -1.5 * scale);
                        txt.AlignmentPoint = insertPt.Convert3D(1 * scale, -1.5 * scale);
                        break;
                    case ArrowDirection.South:  //下

                        refpt = insertPt.Convert3D(width + 2.65 * scale, 0);
                        Array = new Solid(
                           refpt.Convert3D(0, 0, 0),
                           refpt.Convert3D(-2.65 * scale, 0, 0),
                            refpt.Convert3D(-2 * scale, -0.5 * scale, 0)
                           )
                        { Color = Color.FromColorIndex(ColorMethod.ByAci, 7), };

                        modelSpace.AppendEntity(Array);
                        tr.AddNewlyCreatedDBObject(Array, true);
                        line.AddVertexAt(0, insertPt.Convert2D(width), 0, 0, 0);
                        line.AddVertexAt(1, insertPt.Convert2D(), 0, 0, 0);
                        line.AddVertexAt(2, insertPt.Convert2D(0, height), 0, 0, 0);
                        modelSpace.AppendEntity(line);
                        tr.AddNewlyCreatedDBObject(line, true);

                        txt.Position = insertPt.Convert3D(1 * scale, 1.5 * scale);
                        txt.AlignmentPoint = insertPt.Convert3D(1 * scale, 1.5 * scale);
                        break;
                    case ArrowDirection.West:  //左
                        width = 3 * scale;
                        height = 1.5 * scale;
                        refpt = insertPt.Convert3D(0, height + 2.65 * scale);
                        Array = new Solid(
                            refpt.Convert3D(0, 0, 0),
                            refpt.Convert3D(0, -2.65 * scale, 0),
                             refpt.Convert3D(-0.5 * scale, -2 * scale, 0)
                            )
                        { Color = Color.FromColorIndex(ColorMethod.ByAci, 7), };

                        modelSpace.AppendEntity(Array);
                        tr.AddNewlyCreatedDBObject(Array, true);

                        line.AddVertexAt(0, insertPt.Convert2D(width), 0, 0, 0);
                        line.AddVertexAt(1, insertPt.Convert2D(), 0, 0, 0);
                        line.AddVertexAt(2, insertPt.Convert2D(0, height), 0, 0, 0);
                        modelSpace.AppendEntity(line);
                        tr.AddNewlyCreatedDBObject(line, true);

                        txt.Position = insertPt.Convert3D(1 * scale, 1.5 * scale);
                        txt.AlignmentPoint = insertPt.Convert3D(1 * scale, 1.5 * scale);
                        break;
                    case ArrowDirection.East:   //右
                        width = 3 * scale;
                        height = 1.5 * scale;
                        refpt = insertPt.Convert3D(0, height +2.65 * scale);
                        Array = new Solid(
                             refpt.Convert3D(0, 0, 0),
                             refpt.Convert3D(0, -2.65 * scale, 0),
                              refpt.Convert3D(0.5 * scale, -2 * scale, 0)
                             )
                        { Color = Color.FromColorIndex(ColorMethod.ByAci, 7), };

                        modelSpace.AppendEntity(Array);
                        tr.AddNewlyCreatedDBObject(Array, true);
                        line.AddVertexAt(0, insertPt.Convert2D(-width), 0, 0, 0);
                        line.AddVertexAt(1, insertPt.Convert2D(), 0, 0, 0);
                        line.AddVertexAt(2, insertPt.Convert2D(0, height), 0, 0, 0);
                        modelSpace.AppendEntity(line);
                        tr.AddNewlyCreatedDBObject(line, true);

                        txt.Position = insertPt.Convert3D(-1 * scale, 1.5 * scale);
                        txt.AlignmentPoint = insertPt.Convert3D(-1 * scale, 1.5 * scale);
                        break;
                }
                ext = ext.Add(new Extents2d(Array.Bounds.Value.MinPoint.Convert2D(), Array.Bounds.Value.MaxPoint.Convert2D()));
                ext = ext.Add(new Extents2d(line.Bounds.Value.MinPoint.Convert2D(), line.Bounds.Value.MaxPoint.Convert2D()));
                #endregion

                #region

                modelSpace.AppendEntity(txt);
                tr.AddNewlyCreatedDBObject(txt, true);
                ext = ext.Add(new Extents2d(txt.Bounds.Value.MinPoint.Convert2D(), txt.Bounds.Value.MaxPoint.Convert2D()));
                #endregion
                tr.Commit();
            }
        }

        public static void AddPloy4WithLink(Database db, ref Extents2d ext, Point2d upcenter, double wl, double wr, double h, double linkH,string layer="细线")
        {
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder;
                recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                Point2d ptop, pbot;
                Point2d p11, p12, p13, p14;
                Point2d p21, p22, p23, p24;
                Point2d p31, p32, p33, p34;
                ptop = upcenter;
                pbot = upcenter.Convert2D(0, -h);
                p11 = ptop.Convert2D(-wl);
                p12 = pbot.Convert2D(-wl);
                p13 = ptop.Convert2D(wr);
                p14 = pbot.Convert2D(wr);

                double off = (h - linkH) * 0.5;
                p21 = p11.Convert2D(h);
                p22 = p21.Convert2D(0, -off);
                p24 = p13.Convert2D(-h);
                p23 = p24.Convert2D(0, -off);

                p31 = p12.Convert2D(h);
                p32 = p31.Convert2D(0, off);
                p34 = p14.Convert2D(-h);
                p33 = p34.Convert2D(0, off);
                ptop = ptop.Convert2D(0, -off);
                pbot = pbot.Convert2D(0, off);

                Polyline PL1 = new Polyline() { Closed = true,Layer= layer };
                PL1.AddVertexAt(0, ptop, 0, 0, 0);
                PL1.AddVertexAt(1, p22, 0, 0, 0);
                PL1.AddVertexAt(2, p21, 0, 0, 0);
                PL1.AddVertexAt(3, p11, 0, 0, 0);
                PL1.AddVertexAt(4, p12, 0, 0, 0);
                PL1.AddVertexAt(5, p31, 0, 0, 0);
                PL1.AddVertexAt(6, p32, 0, 0, 0);
                PL1.AddVertexAt(7, pbot, 0, 0, 0);
                PL1.AddVertexAt(8, p33, 0, 0, 0);
                PL1.AddVertexAt(9, p34, 0, 0, 0);
                PL1.AddVertexAt(10, p14, 0, 0, 0);
                PL1.AddVertexAt(11, p13, 0, 0, 0);
                PL1.AddVertexAt(12, p24, 0, 0, 0);
                PL1.AddVertexAt(13, p23, 0, 0, 0);

                ext = ext.Add(new Extents2d(PL1.Bounds.Value.MinPoint.Convert2D(), PL1.Bounds.Value.MaxPoint.Convert2D()));

                tr.Commit();
            }
        }


        /// <summary>
        /// 八边形绘图
        /// </summary>
        /// <param name="AnchorPoint">锚点，八边形下中心点</param>
        /// <param name="Height">总高</param>
        /// <param name="Width">总宽</param>
        /// <param name="F1x">下倒角，x方向</param>
        /// <param name="F1y">下倒角，y方向</param>
        /// <param name="F2x">上倒角，x方向</param>
        /// <param name="F2y">上倒角，y方向</param>
        public static void AddPoly8(Database db, ref Extents2d ext, Point2d AnchorPoint, double Height, double Width,

            double F1x = 50, double F1y = 50, double F2x = 50, double F2y = 50, string layer = "细线")
        {
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder;
                recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                Polyline PL1 = new Polyline() { Closed = true,Layer=layer };

                Line2d AxisY = new Line2d(AnchorPoint, AnchorPoint.Convert2D(0, 1));
                Point2d p0, p1, p2, p3, p4, p5, p6, p7;

                p0 = AnchorPoint.Convert2D(-0.5 * Width + F1x, 0);
                p1 = p0.Mirror(AxisY);
                p2 = p1.Convert2D(F1x, F1y);
                p3 = p2.Convert2D(0, Height - F1y - F2y);
                p4 = p3.Convert2D(-F2x, F2y);
                p5 = p4.Mirror(AxisY);
                p6 = p3.Mirror(AxisY);
                p7 = p2.Mirror(AxisY);
                PL1.AddVertexAt(0, p0, 0, 0, 0);
                PL1.AddVertexAt(1, p1, 0, 0, 0);
                PL1.AddVertexAt(2, p2, 0, 0, 0);
                PL1.AddVertexAt(3, p3, 0, 0, 0);
                PL1.AddVertexAt(4, p4, 0, 0, 0);
                PL1.AddVertexAt(5, p5, 0, 0, 0);
                PL1.AddVertexAt(6, p6, 0, 0, 0);
                PL1.AddVertexAt(7, p7, 0, 0, 0);
                ext = ext.Add(new Extents2d(PL1.Bounds.Value.MinPoint.Convert2D(), PL1.Bounds.Value.MaxPoint.Convert2D()));

                tr.Commit();
            }
        }

        public static void AddPloy4(Database db, ref Extents2d ext, Point2d upcenter, double wl, double wr, double h, string layer = "细线")
        {
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder;
                recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                Point2d ptop, pbot;
                Point2d p11, p12, p13, p14;
                ptop = upcenter;
                pbot = upcenter.Convert2D(0, -h);
                p11 = ptop.Convert2D(-wl);
                p12 = pbot.Convert2D(-wl);
                p13 = ptop.Convert2D(wr);
                p14 = pbot.Convert2D(wr);
                Polyline PL1 = new Polyline() { Closed = true,Layer=layer };
                PL1.AddVertexAt(0, p12, 0, 0, 0);
                PL1.AddVertexAt(1, pbot, 0, 0, 0);
                PL1.AddVertexAt(2, p14, 0, 0, 0);

                PL1.AddVertexAt(3, p13, 0, 0, 0);
                PL1.AddVertexAt(4, ptop, 0, 0, 0);
                PL1.AddVertexAt(5, p11, 0, 0, 0);
                recorder.AppendEntity(PL1);
                tr.AddNewlyCreatedDBObject(PL1, true);
                ext = ext.Add(new Extents2d(PL1.Bounds.Value.MinPoint.Convert2D(), PL1.Bounds.Value.MaxPoint.Convert2D()));

                tr.Commit();
            }
        }

        public static void AddPloy4(Database db, ref Extents2d ext, Point2d upcenter, double wl, double wr, double h, double ang, string layer = "细线")
        {
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder;
                recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                Point2d ptop, pbot;
                Point2d p11, p12, p13, p14;
                ptop = upcenter;
                pbot = upcenter.Convert2D(0, -h);
                p11 = ptop.Convert2D(-wl);
                p12 = pbot.Convert2D(-wl);
                p13 = ptop.Convert2D(wr);
                p14 = pbot.Convert2D(wr);
                Polyline PL1 = new Polyline() { Closed = true, Layer = layer };
                PL1.AddVertexAt(0, p12, 0, 0, 0);
                PL1.AddVertexAt(1, pbot, 0, 0, 0);
                PL1.AddVertexAt(2, p14, 0, 0, 0);

                PL1.AddVertexAt(3, p13, 0, 0, 0);
                PL1.AddVertexAt(4, ptop, 0, 0, 0);
                PL1.AddVertexAt(5, p11, 0, 0, 0);
                if(ang!=0)
                  PL1.TransformBy(Matrix3d.Rotation(ang,Vector3d.ZAxis, upcenter.Convert3D(-wl+0.5, -h*0.5)));

                recorder.AppendEntity(PL1);
                tr.AddNewlyCreatedDBObject(PL1, true);
                ext = ext.Add(new Extents2d(PL1.Bounds.Value.MinPoint.Convert2D(), PL1.Bounds.Value.MaxPoint.Convert2D()));

                tr.Commit();
            }
        }


        public static Polyline GetPLAddPloy4(Database db, ref Extents2d ext, Point2d upcenter, double wl, double wr, double h, string layer = "细线")
        {
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder;
                recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                Point2d ptop, pbot;
                Point2d p11, p12, p13, p14;
                ptop = upcenter;
                pbot = upcenter.Convert2D(0, -h);
                p11 = ptop.Convert2D(-wl);
                p12 = pbot.Convert2D(-wl);
                p13 = ptop.Convert2D(wr);
                p14 = pbot.Convert2D(wr);
                Polyline PL1 = new Polyline() { Closed = true, Layer = layer };
                PL1.AddVertexAt(0, p12, 0, 0, 0);
                PL1.AddVertexAt(1, pbot, 0, 0, 0);
                PL1.AddVertexAt(2, p14, 0, 0, 0);

                PL1.AddVertexAt(3, p13, 0, 0, 0);
                PL1.AddVertexAt(4, ptop, 0, 0, 0);
                PL1.AddVertexAt(5, p11, 0, 0, 0);
                recorder.AppendEntity(PL1);
                tr.AddNewlyCreatedDBObject(PL1, true);
                ext = ext.Add(new Extents2d(PL1.Bounds.Value.MinPoint.Convert2D(), PL1.Bounds.Value.MaxPoint.Convert2D()));

                tr.Commit();
                return PL1;
            }
        }


        public static void CreateGirdElev(Database db, ref Extents2d ext, Point2d insertPoint,
            double tWidth, double dia, List<double> topSp,
            int numLayer, double step, out List<Point3d> rebarCC            )
        {
             //width = 0;
            double height = 0;
            double RebarWidth = topSp.Sum();
            double radius = dia * 0.5;
            rebarCC = new List<Point3d>();
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder;

                recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                double x0 = RebarWidth*-0.5;
                double y0 = 0;
                for (int m = 0; m < numLayer; m++)
                {
                    //画线
                    //Polyline line = new Polyline() { Closed = false, Layer = "粗线" };//定义不封闭的Polyline 平面虚线
                    //line.AddVertexAt(0, insertPoint.Convert2D(-0.5*tWidth, -dH), 0, 0, 0);
                    //line.AddVertexAt(1, insertPoint.Convert2D(0.5*tWidth, -dH), 0, 0, 0);
                    Line line = new Line(insertPoint.Convert3D(-0.5 * tWidth, y0), insertPoint.Convert3D(0.5 * tWidth, y0));
                    line.Layer = "粗线";
                    line.ColorIndex = 1;
                    recorder.AppendEntity(line);
                    tr.AddNewlyCreatedDBObject(line, true);
                    ext = ext.Add(new Extents2d(line.Bounds.Value.MinPoint.Convert2D(), line.Bounds.Value.MaxPoint.Convert2D()));
                    #region 
                    //x0 = 0;
                    for (int i = 0; i < topSp.Count+1; i++)
                    {
                        x0 = RebarWidth*(-0.5)+ topSp.GetRange(0, i).Sum();
                        //画圆
                        Circle ci = new Circle();
                        ci.Center = insertPoint.Convert3D(x0, y0 +(Math.Sign(step)) *(radius +1));
                        if (m==0)
                        {
                            rebarCC.Add(ci.Center);

                        }
                        ci.Radius = radius;
                        ci.SetDatabaseDefaults();//用来把圆的颜色、图层、线型、打印样式、可见性等属性设为实体所在的数据库的默认值
                        ci.Layer = "标注";
                        recorder.AppendEntity(ci);
                        tr.AddNewlyCreatedDBObject(ci, true);
                        ext = ext.Add(new Extents2d(ci.Bounds.Value.MinPoint.Convert2D(), ci.Bounds.Value.MaxPoint.Convert2D()));
                        //圆填充
                        ObjectIdCollection collection = new ObjectIdCollection();
                        collection.Add(ci.ObjectId);
                        Hatch hatch = new Hatch();
                        hatch.Elevation = 0;
                        hatch.HatchStyle = HatchStyle.Normal;
                        hatch.ColorIndex = 7;
                        hatch.SetDatabaseDefaults();
                        hatch.SetHatchPattern(HatchPatternType.PreDefined, "SOLID"); //设置填充图案
                        hatch.AppendLoop(HatchLoopTypes.Default, collection); //设置填充边界 //
                        hatch.EvaluateHatch(true);
                        hatch.Layer = "标注";
                        recorder.AppendEntity(hatch);
                        tr.AddNewlyCreatedDBObject(hatch, true);
                    }
                    y0 += step;
                    #endregion
                }

                tr.Commit();
            }
            rebarCC.Sort((x, y) => x.X.CompareTo(y.X));
        }


        public static void CreateLineHatch(Database db, ref Extents2d ext, Point2d Point, double radius,
            List<double> leftSp, List<double> topSp,double tWidth,bool isShowAllLine=false)
        {
            double width = 0;
            double height = 0;
            width = topSp.Sum();
            height = leftSp.Sum();
            double left = (tWidth - width) / 2;
            if (left <= 0)
                left = 0;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder;

                recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                double curWidth = 0;
                double curHeight = 0;              
                for (int m = 0; m < leftSp.Count; m++)
                {
                    //画线
                    Polyline line = new Polyline() { Closed = false, Layer = "粗线" };//定义不封闭的Polyline 平面虚线
                    line.AddVertexAt(0, Point.Convert2D(0- left, -curHeight), 0, 0, 0);
                    line.AddVertexAt(1, Point.Convert2D(width+ left, -curHeight), 0, 0, 0);
                    recorder.AppendEntity(line);
                    tr.AddNewlyCreatedDBObject(line, true);
                    ext = ext.Add(new Extents2d(line.Bounds.Value.MinPoint.Convert2D(), line.Bounds.Value.MaxPoint.Convert2D()));
                    #region 
                    curWidth = 0;
                    for (int i = 0; i < topSp.Count; i++)
                    {
                        if (m == 0)
                        {
                            if (isShowAllLine)
                            {
                                if (i == 0)
                                {
                                    //画线
                                    line = new Polyline() { Closed = false, Layer = "粗线" };//定义不封闭的Polyline 平面虚线
                                    line.AddVertexAt(0, Point.Convert2D(curWidth - left, 0), 0, 0, 0);
                                    line.AddVertexAt(1, Point.Convert2D(curWidth - left, -height), 0, 0, 0);
                                    recorder.AppendEntity(line);
                                    tr.AddNewlyCreatedDBObject(line, true);
                                    ext = ext.Add(new Extents2d(line.Bounds.Value.MinPoint.Convert2D(), line.Bounds.Value.MaxPoint.Convert2D()));
                                }
                                else if (i == topSp.Count-1)
                                {
                                    //画线
                                    line = new Polyline() { Closed = false, Layer = "粗线" };//定义不封闭的Polyline 平面虚线
                                    line.AddVertexAt(0, Point.Convert2D(curWidth +left, 0), 0, 0, 0);
                                    line.AddVertexAt(1, Point.Convert2D(curWidth + left, -height), 0, 0, 0);
                                    recorder.AppendEntity(line);
                                    tr.AddNewlyCreatedDBObject(line, true);
                                    ext = ext.Add(new Extents2d(line.Bounds.Value.MinPoint.Convert2D(), line.Bounds.Value.MaxPoint.Convert2D()));
                                }
                                else
                                {
                                    //画线
                                    line = new Polyline() { Closed = false, Layer = "粗线" };//定义不封闭的Polyline 平面虚线
                                    line.AddVertexAt(0, Point.Convert2D(curWidth, 0), 0, 0, 0);
                                    line.AddVertexAt(1, Point.Convert2D(curWidth, -height), 0, 0, 0);
                                    recorder.AppendEntity(line);
                                    tr.AddNewlyCreatedDBObject(line, true);
                                    ext = ext.Add(new Extents2d(line.Bounds.Value.MinPoint.Convert2D(), line.Bounds.Value.MaxPoint.Convert2D()));
                                }
                            }
                            else
                            {
                                if (i == 0)
                                {
                                    //画线
                                    line = new Polyline() { Closed = false, Layer = "粗线" };//定义不封闭的Polyline 平面虚线
                                    line.AddVertexAt(0, Point.Convert2D(curWidth-left, 0), 0, 0, 0);
                                    line.AddVertexAt(1, Point.Convert2D(curWidth- left, -height), 0, 0, 0);
                                    recorder.AppendEntity(line);
                                    tr.AddNewlyCreatedDBObject(line, true);
                                    ext = ext.Add(new Extents2d(line.Bounds.Value.MinPoint.Convert2D(), line.Bounds.Value.MaxPoint.Convert2D()));
                                }
                            }
                            
                        }
                        //画圆
                        Circle ci = new Circle();
                        ci.Center = Point.Convert3D(curWidth + radius + 0.5, -curHeight - radius - 0.5);
                        ci.Radius = radius;
                        ci.SetDatabaseDefaults();//用来把圆的颜色、图层、线型、打印样式、可见性等属性设为实体所在的数据库的默认值
                        recorder.AppendEntity(ci);
                        tr.AddNewlyCreatedDBObject(ci, true);
                        ext = ext.Add(new Extents2d(ci.Bounds.Value.MinPoint.Convert2D(), ci.Bounds.Value.MaxPoint.Convert2D()));
                        //圆填充
                        ObjectIdCollection collection = new ObjectIdCollection();
                        collection.Add(ci.ObjectId);
                        Hatch hatch = new Hatch();
                        hatch.Elevation = 0;
                        hatch.HatchStyle = HatchStyle.Normal;
                        hatch.ColorIndex = 7;
                        hatch.SetDatabaseDefaults();
                        hatch.SetHatchPattern(HatchPatternType.PreDefined, "SOLID"); //设置填充图案
                        hatch.AppendLoop(HatchLoopTypes.Default, collection); //设置填充边界 //
                        hatch.EvaluateHatch(true);
                        recorder.AppendEntity(hatch);
                        tr.AddNewlyCreatedDBObject(hatch, true);
                        curWidth += topSp[i];
                        if (i == topSp.Count - 1)
                        {
                            if (m == 0)
                            {
                                line = new Polyline() { Closed = false, Layer = "粗线" };//定义不封闭的Polyline 平面虚线
                                line.AddVertexAt(0, Point.Convert2D(curWidth+ left, 0), 0, 0, 0);
                                line.AddVertexAt(1, Point.Convert2D(curWidth+ left, -height), 0, 0, 0);
                                recorder.AppendEntity(line);
                                tr.AddNewlyCreatedDBObject(line, true);
                                ext = ext.Add(new Extents2d(line.Bounds.Value.MinPoint.Convert2D(), line.Bounds.Value.MaxPoint.Convert2D()));
                            }
                            //画圆
                            ci = new Circle();
                            ci.Center = Point.Convert3D(curWidth + radius + 0.5, -curHeight - radius - 0.5);
                            ci.Radius = radius;
                            recorder.AppendEntity(ci);
                            tr.AddNewlyCreatedDBObject(ci, true);
                            ext = ext.Add(new Extents2d(ci.Bounds.Value.MinPoint.Convert2D(), ci.Bounds.Value.MaxPoint.Convert2D()));
                            //圆填充
                            collection = new ObjectIdCollection();
                            collection.Add(ci.ObjectId);
                            hatch = new Hatch();
                            hatch.Elevation = 0;
                            hatch.HatchStyle = HatchStyle.Normal;
                            hatch.ColorIndex = 7;
                            hatch.SetHatchPattern(HatchPatternType.PreDefined, "SOLID"); //设置填充图案
                            hatch.AppendLoop(HatchLoopTypes.Default, collection); //设置填充边界 //
                            hatch.EvaluateHatch(true);
                            recorder.AppendEntity(hatch);
                            tr.AddNewlyCreatedDBObject(hatch, true);
                        }
                    }
                    curHeight += leftSp[m];
                    #endregion
                }

                tr.Commit();
            }
        }
       /// <summary>
       /// 顶层和底层布筋
       /// </summary>
       /// <param name="db"></param>
       /// <param name="ext"></param>
       /// <param name="Point">（最左边作为起点）参考点</param>
       /// <param name="radius">半径</param>
       /// <param name="topSp">间隔列表</param>
       /// <param name="sacle">比例尺</param>
       /// <param name="isOnLineUpper">是否在线上面</param>
        public static void CreateSingleLineHatch(Database db, ref Extents2d ext, Point2d Point, double radius,
         List<double> topSp, double sacle, double Dia, bool isOnLineUpper = true, string layer = "粗线")
        {
            radius = radius * sacle;
            double width = 0;
            width = topSp.Sum();
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder;

                recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                double curWidth = 0;

                //画线
                Polyline line = new Polyline() { Closed = false, Layer = layer, ColorIndex = 1 };//定义不封闭的Polyline 平面虚线
               
                line.AddVertexAt(0, Point.Convert2D(0, 0), 0, 0, 0);
                line.AddVertexAt(1, Point.Convert2D(width+ Dia , 0), 0, 0, 0);
               
                recorder.AppendEntity(line);
                tr.AddNewlyCreatedDBObject(line, true);
                ext = ext.Add(new Extents2d(line.Bounds.Value.MinPoint.Convert2D(), line.Bounds.Value.MaxPoint.Convert2D()));
                #region 
                curWidth = 0;
                for (int i = 0; i < topSp.Count + 1; i++)
                {
                    //画圆
                    Circle ci = new Circle();
                    if (isOnLineUpper)
                    {
                        ci.Center = Point.Convert3D(curWidth + Dia / 2, radius);
                    }
                    else
                    {
                        ci.Center = Point.Convert3D(curWidth + Dia / 2, -radius);
                    }
                    ci.Radius = radius;
                    ci.ColorIndex = 1;
                    ci.SetDatabaseDefaults();//用来把圆的颜色、图层、线型、打印样式、可见性等属性设为实体所在的数据库的默认值
                    recorder.AppendEntity(ci);
                    tr.AddNewlyCreatedDBObject(ci, true);
                    ext = ext.Add(new Extents2d(ci.Bounds.Value.MinPoint.Convert2D(), ci.Bounds.Value.MaxPoint.Convert2D()));
                    //圆填充
                    ObjectIdCollection collection = new ObjectIdCollection();
                    collection.Add(ci.ObjectId);
                    Hatch hatch = new Hatch();
                    hatch.Elevation = 0;
                    hatch.HatchStyle = HatchStyle.Normal;
                    hatch.ColorIndex = 6;
                    hatch.SetDatabaseDefaults();
                    hatch.SetHatchPattern(HatchPatternType.PreDefined, "SOLID"); //设置填充图案
                    hatch.AppendLoop(HatchLoopTypes.Default, collection); //设置填充边界 //
                    hatch.EvaluateHatch(true);
                    recorder.AppendEntity(hatch);
                    tr.AddNewlyCreatedDBObject(hatch, true);
                    if (i < topSp.Count)
                        curWidth += topSp[i];
                }

                #endregion


                tr.Commit();
            }
        }
        /// <summary>
        /// 侧面布筋
        /// </summary>
        /// <param name="db"></param>
        /// <param name="ext"></param>
        /// <param name="Point">（最下面作为起点）参考点</param>
        /// <param name="radius">半径</param>
        /// <param name="topSp">侧面间隔集合</param>
        /// <param name="sacle">比例尺</param>
        /// <param name="bH">底层钢筋高度</param>
        /// <param name="isOnLineRight">是否在右边</param>
        public static void CreateSideSingleLineHatch(Database db, ref Extents2d ext, Point2d Point, double radius,
    List<double> sideSp, double sacle, double Dia, double bH = 0, bool isOnLineRight = true,string layer= "粗线",bool isAddDia=false)
        {
            radius = radius * sacle;
            double height = 0;
            height = sideSp.Sum();
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder;

                recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                double curHeight = 0;

                //画线
                Polyline line = new Polyline() { Closed = false, Layer = layer,ColorIndex=1 };//定义不封闭的Polyline 平面虚线
               
                line.AddVertexAt(0, Point.Convert2D(0, -bH), 0, 0, 0);
                if(isAddDia)
                    line.AddVertexAt(1, Point.Convert2D(0, height + Dia/2 + Dia/2), 0, 0, 0);
                else
                  line.AddVertexAt(1, Point.Convert2D(0, height + Dia/2), 0, 0, 0);
              
                recorder.AppendEntity(line);
                tr.AddNewlyCreatedDBObject(line, true);
                ext = ext.Add(new Extents2d(line.Bounds.Value.MinPoint.Convert2D(), line.Bounds.Value.MaxPoint.Convert2D()));
                #region 
                curHeight = 0;
                for (int i = 0; i < sideSp.Count; i++)
                {
                    if (i > 0)
                    {
                        //画圆
                        Circle ci = new Circle();
                        if (isOnLineRight)
                        {
                            ci.Center = Point.Convert3D(radius, curHeight + Dia / 2);
                        }
                        else
                        {
                            ci.Center = Point.Convert3D(-radius, curHeight + Dia / 2);
                        }
                        ci.Radius = radius;
                        ci.ColorIndex = 1;
                        ci.SetDatabaseDefaults();//用来把圆的颜色、图层、线型、打印样式、可见性等属性设为实体所在的数据库的默认值
                        recorder.AppendEntity(ci);
                        tr.AddNewlyCreatedDBObject(ci, true);
                        ext = ext.Add(new Extents2d(ci.Bounds.Value.MinPoint.Convert2D(), ci.Bounds.Value.MaxPoint.Convert2D()));
                        //圆填充
                        ObjectIdCollection collection = new ObjectIdCollection();
                        collection.Add(ci.ObjectId);
                        Hatch hatch = new Hatch();
                        hatch.Elevation = 0;
                        hatch.HatchStyle = HatchStyle.Normal;
                        hatch.ColorIndex = 6;
                        hatch.SetDatabaseDefaults();
                        hatch.SetHatchPattern(HatchPatternType.PreDefined, "SOLID"); //设置填充图案
                        hatch.AppendLoop(HatchLoopTypes.Default, collection); //设置填充边界 //
                        hatch.EvaluateHatch(true);
                        recorder.AppendEntity(hatch);
                        tr.AddNewlyCreatedDBObject(hatch, true);
                    }
                    if (i < sideSp.Count)
                        curHeight += sideSp[i];
                }

                #endregion


                tr.Commit();
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="db"></param>
        /// <param name="Point"></param>
        /// <param name="leftSp"></param>
        /// <param name="topSp"></param>
        /// <param name="ext"></param>
        /// <param name="exLength"></param>
        /// <param name="PtsLeft">左侧标注基点</param>
        /// <param name="PtsTop">顶部标注基点</param>
        public static void CreateLineGrid(Database db, Point2d Point, List<double> leftSp, List<double> topSp ,ref Extents2d ext,double exLength,
            out List<Point3d> PtsLeft,out List<Point3d> PtsTop)
        {
            double width = 0;
            double height = 0;
            width = topSp.Sum();
            height = leftSp.Sum();
            double curWidth = 0;
            double curHeight = 0;

            //             输出横纵向PT列表
            PtsLeft = new List<Point3d>(); // 左侧列表
            PtsTop = new List<Point3d>();  // 顶部列表
            //             输出横纵向PT列表

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder;

                recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                for (int m = 0; m < leftSp.Count; m++)
                {
                    //画线
                    Polyline line = new Polyline() { Closed = false, Layer = "粗线" };//定义不封闭的Polyline 平面虚线
                    line.AddVertexAt(0, Point.Convert2D(0- exLength, -curHeight), 0, 0, 0);
                    PtsLeft.Add(Point.Convert3D(0 , -curHeight));
                    line.AddVertexAt(1, Point.Convert2D(width+ exLength, -curHeight), 0, 0, 0);
                    recorder.AppendEntity(line);
                    tr.AddNewlyCreatedDBObject(line, true);
                    ext = ext.Add(new Extents2d(line.Bounds.Value.MinPoint.Convert2D(), line.Bounds.Value.MaxPoint.Convert2D()));
                    #region 
                    curWidth = 0;
                    for (int i = 0; i < topSp.Count; i++)
                    {
                        if (m == 0)
                        {
                            //画线
                            line = new Polyline() { Closed = false, Layer = "粗线" };//定义不封闭的Polyline 平面虚线
                            line.AddVertexAt(0, Point.Convert2D(curWidth, 0+ exLength), 0, 0, 0);
                            PtsTop.Add(Point.Convert3D(curWidth, 0));
                            line.AddVertexAt(1, Point.Convert2D(curWidth, -height- exLength), 0, 0, 0);
                            recorder.AppendEntity(line);
                            tr.AddNewlyCreatedDBObject(line, true);
                            ext = ext.Add(new Extents2d(line.Bounds.Value.MinPoint.Convert2D(), line.Bounds.Value.MaxPoint.Convert2D()));
                        }

                        curWidth += topSp[i];
                        if (i == topSp.Count - 1)
                        {
                            if (m == 0)
                            {
                                //画线
                                line = new Polyline() { Closed = false, Layer = "粗线" };//定义不封闭的Polyline 平面虚线
                                line.AddVertexAt(0, Point.Convert2D(curWidth, 0 + exLength), 0, 0, 0);
                                PtsTop.Add(Point.Convert3D(curWidth, 0));
                                line.AddVertexAt(1, Point.Convert2D(curWidth, -height- exLength), 0, 0, 0);
                                recorder.AppendEntity(line);
                                tr.AddNewlyCreatedDBObject(line, true);
                                ext = ext.Add(new Extents2d(line.Bounds.Value.MinPoint.Convert2D(), line.Bounds.Value.MaxPoint.Convert2D()));
                            }
                        }


                    }
                    curHeight += leftSp[m];
                    if (m == leftSp.Count - 1)
                    {
                        //画线
                        line = new Polyline() { Closed = false, Layer = "粗线" };//定义不封闭的Polyline 平面虚线
                        line.AddVertexAt(0, Point.Convert2D(0- exLength, -height), 0, 0, 0);
                        PtsLeft.Add(Point.Convert3D(0, -height));
                        line.AddVertexAt(1, Point.Convert2D(width + exLength, -height), 0, 0, 0);
                        recorder.AppendEntity(line);
                        tr.AddNewlyCreatedDBObject(line, true);
                        ext = ext.Add(new Extents2d(line.Bounds.Value.MinPoint.Convert2D(), line.Bounds.Value.MaxPoint.Convert2D()));
                    }
                    #endregion
                }
                tr.Commit();

            }

            PtsTop.Sort((x, y) => x.X.CompareTo(y.X));
            PtsLeft.Sort((x, y) => x.Y.CompareTo(y.Y));
        }

        public static void CreateMultiLineCicle(Database db, ref Extents2d ext, Point3d refpt,List<Point3d> listP,string textstring = "1", double scale = 1)
        {
   
            double cR = 2.5;
            DBText txt = new DBText();
            Circle C2 = new Circle();
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                bool isUp = true;
                if(listP.Count>0)
                {
                    foreach(var p in listP)
                    {
                        Line line = new Line(p, refpt);
                        line.Layer = "细线";
                        modelSpace.AppendEntity(line);
                        tr.AddNewlyCreatedDBObject(line, true);
                        ext = ext.Add(new Extents2d(line.Bounds.Value.MinPoint.Convert2D(), line.Bounds.Value.MaxPoint.Convert2D()));
                    }
                    if(listP[0].Y>refpt.Y)
                    {
                        isUp = false;
                    }
                }
                double height = cR * scale;
                if(!isUp)
                    height= -cR * scale;
                txt.TextString = textstring.ToString();
                txt.Height = 2.5 * scale;
                txt.Position = refpt.Convert3D(0, height);
                txt.HorizontalMode = TextHorizontalMode.TextCenter;
                txt.VerticalMode = TextVerticalMode.TextVerticalMid;
                txt.AlignmentPoint = refpt.Convert3D(0, height);
                txt.TextStyleId = st[Extensions.curFont];
                txt.ColorIndex = 4;
                txt.Layer = "细线";
                txt.WidthFactor = 0.8;

                C2 = new Circle(refpt.Convert3D(0, height), Vector3d.ZAxis, cR * scale);
                C2.Layer = "细线";
                C2.ColorIndex = 4;
                modelSpace.AppendEntity(txt);
                tr.AddNewlyCreatedDBObject(txt, true);
                modelSpace.AppendEntity(C2);
                tr.AddNewlyCreatedDBObject(C2, true);
                ext = ext.Add(new Extents2d(txt.Bounds.Value.MinPoint.Convert2D(), txt.Bounds.Value.MaxPoint.Convert2D()));
                ext = ext.Add(new Extents2d(C2.Bounds.Value.MinPoint.Convert2D(), C2.Bounds.Value.MaxPoint.Convert2D()));
                tr.Commit();
            }
        }
        /// <summary>
        /// 画线和圆
        /// </summary>
        /// <param name="db"></param>
        /// <param name="ext"></param>
        /// <param name="listLinePoint">多线点集合</param>
        /// <param name="listCirclePoint">圆集合</param>
        /// <param name="tWidth"></param>
        /// <param name="dia"></param>
        /// <param name="scale"></param>
        public static void CreateLineCicles(Database db, ref Extents2d ext,List<Point3d> listLinePoint, List<Point3d> listCirclePoint, double tWidth, double dia, double scale = 1)
        {
            double radius = dia * 0.5;
            Polyline line = new Polyline() { Closed = false, Layer = "粗线" };
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;               
                if (listLinePoint.Count > 0)
                {
                    foreach (var p in listLinePoint)
                    {
                        line.AddVertexAt(0, p.Convert2D(), 0, 0, 0);                      
                    }
                    recorder.AppendEntity(line);
                    tr.AddNewlyCreatedDBObject(line, true);
                    ext = ext.Add(new Extents2d(line.Bounds.Value.MinPoint.Convert2D(), line.Bounds.Value.MaxPoint.Convert2D()));
                }
                if (listCirclePoint.Count > 0)
                {
                    foreach (var p in listCirclePoint)
                    {
                        Circle ci = new Circle();
                        ci.Center = p.Convert3D(0, radius + 1);
                       
                        ci.Radius = radius;
                        ci.SetDatabaseDefaults();//用来把圆的颜色、图层、线型、打印样式、可见性等属性设为实体所在的数据库的默认值
                        ci.Layer = "粗线";
                        recorder.AppendEntity(ci);
                        tr.AddNewlyCreatedDBObject(ci, true);
                        ext = ext.Add(new Extents2d(ci.Bounds.Value.MinPoint.Convert2D(), ci.Bounds.Value.MaxPoint.Convert2D()));
                        //圆填充
                        ObjectIdCollection collection = new ObjectIdCollection();
                        collection.Add(ci.ObjectId);
                        Hatch hatch = new Hatch();
                        hatch.Elevation = 0;
                        hatch.HatchStyle = HatchStyle.Normal;
                        hatch.ColorIndex = 7;
                        hatch.SetDatabaseDefaults();
                        hatch.SetHatchPattern(HatchPatternType.PreDefined, "SOLID"); //设置填充图案
                        hatch.AppendLoop(HatchLoopTypes.Default, collection); //设置填充边界 //
                        hatch.EvaluateHatch(true);
                        hatch.Layer = "粗线";
                        recorder.AppendEntity(hatch);
                        tr.AddNewlyCreatedDBObject(hatch, true);
                    }
                   
                }           
                tr.Commit();
            }
        }

       /// <summary>
       /// 箭头标注
       /// </summary>
       /// <param name="db"></param>
       /// <param name="ext"></param>
       /// <param name="refpt"></param>
       /// <param name="arrDir"></param>
       /// <param name="leftSp"></param>
       /// <param name="topSp"></param>
       /// <param name="textstring"></param>
       /// <param name="scale"></param>
       /// <param name="isLastVisible"></param>
       /// <param name="length"></param>
        public static void CreateLineArrowDB(Database db, ref Extents2d ext, Point3d refpt, ArrowDirection arrDir, List<double> leftSp, List<double> topSp, string textstring = "1", double scale = 1, bool isLastVisible = true,double length=0)
        {
            double width = 0;
            double height = 0;
            width = topSp.Sum();
            height = leftSp.Sum();
            double curWidth = 0;
            double curHeight = 0;
            double cR = 2.5;
            DBText txt = new DBText();
            Circle C2 = new Circle();
            Point3d PositionPoint;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                Solid Array=new Solid();
                Line L=new Line() { Layer = "细线", ColorIndex=4};
                switch (arrDir)
                {
                    case ArrowDirection.East:  //右
                        refpt = refpt.Convert3D(width, 0);
                        if (topSp.Count > 0)
                        {
                            for (int i = 0; i < topSp.Count; i++)
                            {
                                Array = new Solid(
                                 refpt.Convert3D(0 - curWidth, 0, 0),
                                 refpt.Convert3D(-2.65 * scale - curWidth, 0, 0),
                                  refpt.Convert3D(-2 * scale - curWidth, 0.5 * scale, 0)
                                 )
                                { Color = Color.FromColorIndex(ColorMethod.ByAci, 4), Layer = "细线", };
                                modelSpace.AppendEntity(Array);
                                tr.AddNewlyCreatedDBObject(Array, true);
                                curWidth += topSp[topSp.Count - 1 - i];
                                if (i == topSp.Count - 1&& isLastVisible)
                                {
                                    Array = new Solid(
                                 refpt.Convert3D(0 - curWidth, 0, 0),
                                 refpt.Convert3D(-2.65 * scale - curWidth, 0, 0),
                                  refpt.Convert3D(-2 * scale - curWidth, 0.5 * scale, 0)
                                 )
                                    { Color = Color.FromColorIndex(ColorMethod.ByAci, 4), Layer = "细线", };
                                    modelSpace.AppendEntity(Array);
                                    tr.AddNewlyCreatedDBObject(Array, true);
                                }
                            }
                        }
                        else
                        {
                            Array = new Solid(
                                 refpt.Convert3D(0 - curWidth, 0, 0),
                                 refpt.Convert3D(-2.65 * scale - curWidth, 0, 0),
                                  refpt.Convert3D(-2 * scale - curWidth, 0.5 * scale, 0)
                                 )
                            { Color = Color.FromColorIndex(ColorMethod.ByAci, 4), Layer = "细线", };
                            modelSpace.AppendEntity(Array);
                            tr.AddNewlyCreatedDBObject(Array, true);
                        }
                        L = new Line(refpt.Convert3D(-width - (4+length)* scale, 0, 0), refpt.Convert3D(0, 0, 0))
                        { Color = Color.FromColorIndex(ColorMethod.ByAci, 4),Layer="细线", };
                        modelSpace.AppendEntity(L);
                        tr.AddNewlyCreatedDBObject(L, true);
                        PositionPoint = refpt.Convert3D(-width - (4 + length) * scale - cR* scale, 0, 0);
                        break;
                    case ArrowDirection.West:  //左
                        if (topSp.Count > 0)
                        {
                            for (int i = 0; i < topSp.Count; i++)
                            {
                                Array = new Solid(
                             refpt.Convert3D(0 + curWidth, 0, 0),
                             refpt.Convert3D(2.65 * scale + curWidth, 0, 0),
                              refpt.Convert3D(2 * scale + curWidth, 0.5 * scale, 0)
                             )
                                { Color = Color.FromColorIndex(ColorMethod.ByAci, 4), Layer = "细线", };

                                modelSpace.AppendEntity(Array);
                                tr.AddNewlyCreatedDBObject(Array, true);
                                curWidth += topSp[i];
                                if (i == topSp.Count - 1&&isLastVisible)
                                {
                                    Array = new Solid(
                             refpt.Convert3D(0 + curWidth, 0, 0),
                             refpt.Convert3D(2.65 * scale + curWidth, 0, 0),
                              refpt.Convert3D(2 * scale + curWidth, 0.5 * scale, 0)
                             )
                                    { Color = Color.FromColorIndex(ColorMethod.ByAci, 4), Layer = "细线", };

                                    modelSpace.AppendEntity(Array);
                                    tr.AddNewlyCreatedDBObject(Array, true);
                                }
                            }
                        }
                        else
                        {
                            Array = new Solid(
                           refpt.Convert3D(0 + curWidth, 0, 0),
                           refpt.Convert3D(2.65 * scale + curWidth, 0, 0),
                            refpt.Convert3D(2 * scale + curWidth, 0.5 * scale, 0)
                           )
                            { Color = Color.FromColorIndex(ColorMethod.ByAci, 4), Layer = "细线", };

                            modelSpace.AppendEntity(Array);
                            tr.AddNewlyCreatedDBObject(Array, true);
                        }
                        L = new Line(refpt.Convert3D(width + (4 + length) * scale, 0, 0), refpt.Convert3D(0, 0, 0))
                        { Color = Color.FromColorIndex(ColorMethod.ByAci, 4), Layer = "细线", };
                        modelSpace.AppendEntity(L);
                        tr.AddNewlyCreatedDBObject(L, true);
                        PositionPoint = refpt.Convert3D(width + (4 + length) * scale + cR* scale, 0, 0);
                        break;
                    case ArrowDirection.South:  //下
                        refpt = refpt.Convert3D(0, -height);
                        if (leftSp.Count > 0)
                        {
                            for (int i = 0; i < leftSp.Count; i++)
                            {
                                Array = new Solid(
                             refpt.Convert3D(0, 0 + curHeight, 0),
                             refpt.Convert3D(0, 2.65 * scale + curHeight, 0),
                              refpt.Convert3D(0.5 * scale, 2 * scale + curHeight, 0)
                             )
                                { Color = Color.FromColorIndex(ColorMethod.ByAci, 4), Layer = "细线", };

                                modelSpace.AppendEntity(Array);
                                tr.AddNewlyCreatedDBObject(Array, true);
                                curHeight += leftSp[leftSp.Count - 1 - i];
                                if (i == leftSp.Count - 1 && isLastVisible)
                                {
                                    Array = new Solid(
                           refpt.Convert3D(0, 0 + curHeight, 0),
                           refpt.Convert3D(0, 2.65 * scale + curHeight, 0),
                            refpt.Convert3D(0.5 * scale, 2 * scale + curHeight, 0)
                           )
                                    { Color = Color.FromColorIndex(ColorMethod.ByAci, 4), Layer = "细线", };

                                    modelSpace.AppendEntity(Array);
                                    tr.AddNewlyCreatedDBObject(Array, true);
                                }
                            }
                        }
                        else
                        {
                            Array = new Solid(
                            refpt.Convert3D(0, 0 + curHeight, 0),
                            refpt.Convert3D(0, 2.65 * scale + curHeight, 0),
                             refpt.Convert3D(0.5 * scale, 2 * scale + curHeight, 0)
                            )
                            { Color = Color.FromColorIndex(ColorMethod.ByAci, 4), Layer = "细线", };

                            modelSpace.AppendEntity(Array);
                            tr.AddNewlyCreatedDBObject(Array, true);
                        }
                        L = new Line(refpt.Convert3D(0, height + (4 + length) * scale, 0), refpt.Convert3D(0, 0, 0))
                        { Color = Color.FromColorIndex(ColorMethod.ByAci, 4), Layer = "细线", };
                        modelSpace.AppendEntity(L);
                        tr.AddNewlyCreatedDBObject(L, true);
                        PositionPoint = refpt.Convert3D(0, height + (4 + length) * scale + cR* scale, 0);
                        break;
                    case ArrowDirection.North:   //上
                        if (leftSp.Count > 0)
                        {
                            for (int i = 0; i < leftSp.Count; i++)
                            {
                                Array = new Solid(
                             refpt.Convert3D(0, 0 - curHeight, 0),
                             refpt.Convert3D(0, -2.65 * scale - curHeight, 0),
                              refpt.Convert3D(0.5 * scale, -2 * scale - curHeight, 0)
                             )
                                { Color = Color.FromColorIndex(ColorMethod.ByAci, 4), Layer = "细线", };

                                modelSpace.AppendEntity(Array);
                                tr.AddNewlyCreatedDBObject(Array, true);
                                curHeight += leftSp[i];
                                if (i == leftSp.Count && isLastVisible)
                                {
                                    Array = new Solid(
                            refpt.Convert3D(0, 0 - curHeight, 0),
                            refpt.Convert3D(0, -2.65 * scale - curHeight, 0),
                             refpt.Convert3D(0.5 * scale, -2 * scale - curHeight, 0)
                            )
                                    { Color = Color.FromColorIndex(ColorMethod.ByAci, 4), Layer = "细线", };

                                    modelSpace.AppendEntity(Array);
                                    tr.AddNewlyCreatedDBObject(Array, true);
                                }
                            }
                        }
                        else
                        {
                            Array = new Solid(
                             refpt.Convert3D(0, 0 - curHeight, 0),
                             refpt.Convert3D(0, -2.65 * scale - curHeight, 0),
                              refpt.Convert3D(0.5 * scale, -2 * scale - curHeight, 0)
                             )
                            { Color = Color.FromColorIndex(ColorMethod.ByAci, 4), Layer = "细线", };

                            modelSpace.AppendEntity(Array);
                            tr.AddNewlyCreatedDBObject(Array, true);
                        }
                        L = new Line(refpt.Convert3D(0, -height - (4 + length) * scale, 0), refpt.Convert3D(0, 0, 0))
                        { Color = Color.FromColorIndex(ColorMethod.ByAci, 4), Layer = "细线", };
                        modelSpace.AppendEntity(L);
                        tr.AddNewlyCreatedDBObject(L, true);
                        PositionPoint = refpt.Convert3D(0, -height - (4 + length) * scale - cR* scale, 0);
                        break;
                    default:  //右
                        refpt = refpt.Convert3D(width, 0);
                        for (int i = 0; i < topSp.Count; i++)
                        {
                            Array = new Solid(
                             refpt.Convert3D(0 - curWidth, 0, 0),
                             refpt.Convert3D(-2.65 * scale - curWidth, 0, 0),
                              refpt.Convert3D(-2 * scale - curWidth, 0.5 * scale, 0)
                             )
                            { Color = Color.FromColorIndex(ColorMethod.ByAci, 4), Layer = "细线", };
                            modelSpace.AppendEntity(Array);
                            tr.AddNewlyCreatedDBObject(Array, true);
                            curWidth += topSp[topSp.Count - 1 - i];
                        }
                        L = new Line(refpt.Convert3D(-width - (4 + length) * scale, 0, 0), refpt.Convert3D(0, 0, 0))
                        { Color = Color.FromColorIndex(ColorMethod.ByAci, 4), Layer = "细线", };
                        modelSpace.AppendEntity(L);
                        tr.AddNewlyCreatedDBObject(L, true);
                        PositionPoint = refpt.Convert3D(-width - (4 + length) * scale - cR * scale, 0, 0);
                        break;
                }
                ext = ext.Add(new Extents2d(Array.Bounds.Value.MinPoint.Convert2D(), Array.Bounds.Value.MaxPoint.Convert2D()));
                ext = ext.Add(new Extents2d(L.Bounds.Value.MinPoint.Convert2D(), L.Bounds.Value.MaxPoint.Convert2D()));
                txt.TextString = textstring.ToString();
                txt.Height = 2.5 * scale;
                txt.Position = PositionPoint.Convert3D();
                txt.HorizontalMode = TextHorizontalMode.TextCenter;
                txt.VerticalMode = TextVerticalMode.TextVerticalMid;
                txt.AlignmentPoint = PositionPoint.Convert3D();
                txt.TextStyleId = st[Extensions.curFont];
                txt.Layer = "标注";
                txt.ColorIndex = 4;
                txt.WidthFactor = 0.8;

                C2 = new Circle(PositionPoint.Convert3D(), Vector3d.ZAxis, cR * scale);
                C2.Layer = "标注";
                C2.ColorIndex = 4;
                modelSpace.AppendEntity(txt);
                tr.AddNewlyCreatedDBObject(txt, true);
                modelSpace.AppendEntity(C2);
                tr.AddNewlyCreatedDBObject(C2, true);
                ext = ext.Add(new Extents2d(txt.Bounds.Value.MinPoint.Convert2D(), txt.Bounds.Value.MaxPoint.Convert2D()));
                ext = ext.Add(new Extents2d(C2.Bounds.Value.MinPoint.Convert2D(), C2.Bounds.Value.MaxPoint.Convert2D()));
                tr.Commit();
            }
        }

        /// <summary>
        /// 箭头
        /// </summary>
        /// <param name="db"></param>
        /// <param name="ext"></param>
        /// <param name="refpt"></param>
        /// <param name="arrDir"></param>
        /// <param name="leftSp"></param>
        /// <param name="topSp"></param>
        /// <param name="textstring"></param>
        /// <param name="scale"></param>
        /// <param name="isLastVisible"></param>
        /// <param name="length"></param>
        /// <param name="leftLength">上下标注折线长度</param>
        public static void CreateLineArrowDBNew(Database db, ref Extents2d ext, Point3d refpt, ArrowDirection arrDir, List<double> leftSp, List<double> topSp, string textstring = "1", double scale = 1, bool isLastVisible = true, double length = 0,double leftLength=0)
        {
            double width = 0;
            double height = 0;
            width = topSp.Sum();
            height = leftSp.Sum();
            double curWidth = 0;
            double curHeight = 0;
            double cR = 2.5;
            DBText txt = new DBText();
            Circle C2 = new Circle();
            Point3d PositionPoint;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                Solid Array = new Solid();
                Line L = new Line() { Layer = "细线", ColorIndex = 4 };
                switch (arrDir)
                {
                    case ArrowDirection.East:  //右
                        refpt = refpt.Convert3D(width, 0);
                        if (topSp.Count > 0)
                        {
                            for (int i = 0; i < topSp.Count; i++)
                            {
                                Array = new Solid(
                                 refpt.Convert3D(0 - curWidth, 0, 0),
                                 refpt.Convert3D(-0.01 * scale - curWidth, 0, 0),
                                  refpt.Convert3D(-1 * scale - curWidth, 0.5 * scale, 0)
                                 )
                                { Color = Color.FromColorIndex(ColorMethod.ByAci, 4), Layer = "细线", };
                                modelSpace.AppendEntity(Array);
                                tr.AddNewlyCreatedDBObject(Array, true);
                                curWidth += topSp[topSp.Count - 1 - i];
                                if (i == topSp.Count - 1 && isLastVisible)
                                {
                                    Array = new Solid(
                                 refpt.Convert3D(0 - curWidth, 0, 0),
                                 refpt.Convert3D(-0.01 * scale - curWidth, 0, 0),
                                  refpt.Convert3D(-1 * scale - curWidth, 0.5 * scale, 0)
                                 )
                                    { Color = Color.FromColorIndex(ColorMethod.ByAci, 4), Layer = "细线", };
                                    modelSpace.AppendEntity(Array);
                                    tr.AddNewlyCreatedDBObject(Array, true);
                                }
                            }
                        }
                        else
                        {
                            Array = new Solid(
                                 refpt.Convert3D(0 - curWidth, 0, 0),
                                 refpt.Convert3D(-0.01 * scale - curWidth, 0, 0),
                                  refpt.Convert3D(-1 * scale - curWidth, 0.5 * scale, 0)
                                 )
                            { Color = Color.FromColorIndex(ColorMethod.ByAci, 4), Layer = "细线", };
                            modelSpace.AppendEntity(Array);
                            tr.AddNewlyCreatedDBObject(Array, true);
                        }
                        L = new Line(refpt.Convert3D(-width - (1 + length) * scale, 0, 0), refpt.Convert3D(0, 0, 0))
                        { Color = Color.FromColorIndex(ColorMethod.ByAci, 4), Layer = "细线", };
                        modelSpace.AppendEntity(L);
                        tr.AddNewlyCreatedDBObject(L, true);
                        PositionPoint = refpt.Convert3D(-width - (1 + length) * scale - cR * scale, 0, 0);
                        break;
                    case ArrowDirection.West:  //左
                        if (topSp.Count > 0)
                        {
                            for (int i = 0; i < topSp.Count; i++)
                            {
                                Array = new Solid(
                             refpt.Convert3D(0 + curWidth, 0, 0),
                             refpt.Convert3D(0.01 * scale + curWidth, 0, 0),
                              refpt.Convert3D(1 * scale + curWidth, 0.5 * scale, 0)
                             )
                                { Color = Color.FromColorIndex(ColorMethod.ByAci, 4), Layer = "细线", };

                                modelSpace.AppendEntity(Array);
                                tr.AddNewlyCreatedDBObject(Array, true);
                                curWidth += topSp[i];
                                if (i == topSp.Count - 1 && isLastVisible)
                                {
                                    Array = new Solid(
                             refpt.Convert3D(0 + curWidth, 0, 0),
                             refpt.Convert3D(0.01 * scale + curWidth, 0, 0),
                              refpt.Convert3D(1 * scale + curWidth, 0.5 * scale, 0)
                             )
                                    { Color = Color.FromColorIndex(ColorMethod.ByAci, 4), Layer = "细线", };

                                    modelSpace.AppendEntity(Array);
                                    tr.AddNewlyCreatedDBObject(Array, true);
                                }
                            }
                        }
                        else
                        {
                            Array = new Solid(
                           refpt.Convert3D(0 + curWidth, 0, 0),
                           refpt.Convert3D(0.01 * scale + curWidth, 0, 0),
                            refpt.Convert3D(1 * scale + curWidth, 0.5 * scale, 0)
                           )
                            { Color = Color.FromColorIndex(ColorMethod.ByAci, 4), Layer = "细线", };

                            modelSpace.AppendEntity(Array);
                            tr.AddNewlyCreatedDBObject(Array, true);
                        }
                        L = new Line(refpt.Convert3D(width + (1 + length) * scale, 0, 0), refpt.Convert3D(0, 0, 0))
                        { Color = Color.FromColorIndex(ColorMethod.ByAci, 4), Layer = "细线", };
                        modelSpace.AppendEntity(L);
                        tr.AddNewlyCreatedDBObject(L, true);
                        PositionPoint = refpt.Convert3D(width + (1 + length) * scale + cR * scale, 0, 0);
                        break;
                    case ArrowDirection.South:  //下
                        refpt = refpt.Convert3D(0, -height);
                        if (leftSp.Count > 0)
                        {
                            for (int i = 0; i < leftSp.Count; i++)
                            {
                                Array = new Solid(
                             refpt.Convert3D(0, 0 + curHeight, 0),
                             refpt.Convert3D(0, 0.01 * scale + curHeight, 0),
                              refpt.Convert3D(0.5 * scale, 1 * scale + curHeight, 0)
                             )
                                { Color = Color.FromColorIndex(ColorMethod.ByAci, 4), Layer = "细线", };

                                modelSpace.AppendEntity(Array);
                                tr.AddNewlyCreatedDBObject(Array, true);
                                curHeight += leftSp[leftSp.Count - 1 - i];
                                if (i == leftSp.Count - 1 && isLastVisible)
                                {
                                    Array = new Solid(
                           refpt.Convert3D(0, 0 + curHeight, 0),
                           refpt.Convert3D(0, 0.01 * scale + curHeight, 0),
                            refpt.Convert3D(0.5 * scale, 1 * scale + curHeight, 0)
                           )
                                    { Color = Color.FromColorIndex(ColorMethod.ByAci, 4), Layer = "细线", };

                                    modelSpace.AppendEntity(Array);
                                    tr.AddNewlyCreatedDBObject(Array, true);
                                }
                            }
                        }
                        else
                        {
                            Array = new Solid(
                            refpt.Convert3D(0, 0 + curHeight, 0),
                            refpt.Convert3D(0, 0.01 * scale + curHeight, 0),
                             refpt.Convert3D(0.5 * scale, 1 * scale + curHeight, 0)
                            )
                            { Color = Color.FromColorIndex(ColorMethod.ByAci, 4), Layer = "细线", };

                            modelSpace.AppendEntity(Array);
                            tr.AddNewlyCreatedDBObject(Array, true);
                        }
                        L = new Line(refpt.Convert3D(0, height + (1 + length) * scale, 0), refpt.Convert3D(0, 0, 0))
                        { Color = Color.FromColorIndex(ColorMethod.ByAci, 4), Layer = "细线", };
                        modelSpace.AppendEntity(L);
                        tr.AddNewlyCreatedDBObject(L, true);
                        if (leftLength > 0)
                        {
                            L = new Line(refpt.Convert3D(leftLength, height + (1 + length) * scale, 0), refpt.Convert3D(0, height + (1+ length) * scale, 0))
                            { Color = Color.FromColorIndex(ColorMethod.ByAci, 4), Layer = "细线", };
                            modelSpace.AppendEntity(L);
                            tr.AddNewlyCreatedDBObject(L, true);
                            PositionPoint = refpt.Convert3D(leftLength + cR * scale, height + (1 + length) * scale, 0);
                        }
                        else
                        {
                            PositionPoint = refpt.Convert3D(0, height + (1+ length) * scale + cR * scale, 0);
                        }
                        break;
                    case ArrowDirection.North:   //上
                        if (leftSp.Count > 0)
                        {
                            for (int i = 0; i < leftSp.Count; i++)
                            {
                                Array = new Solid(
                             refpt.Convert3D(0, 0 - curHeight, 0),
                             refpt.Convert3D(0, -0.01 * scale - curHeight, 0),
                              refpt.Convert3D(0.5 * scale, -1 * scale - curHeight, 0)
                             )
                                { Color = Color.FromColorIndex(ColorMethod.ByAci, 4), Layer = "细线", };

                                modelSpace.AppendEntity(Array);
                                tr.AddNewlyCreatedDBObject(Array, true);
                                curHeight += leftSp[i];
                                if (i == leftSp.Count && isLastVisible)
                                {
                                    Array = new Solid(
                            refpt.Convert3D(0, 0 - curHeight, 0),
                            refpt.Convert3D(0, -0.01 * scale - curHeight, 0),
                             refpt.Convert3D(0.5 * scale, -1 * scale - curHeight, 0)
                            )
                                    { Color = Color.FromColorIndex(ColorMethod.ByAci, 4), Layer = "细线", };

                                    modelSpace.AppendEntity(Array);
                                    tr.AddNewlyCreatedDBObject(Array, true);
                                }
                            }
                        }
                        else
                        {
                            Array = new Solid(
                             refpt.Convert3D(0, 0 - curHeight, 0),
                             refpt.Convert3D(0, -0.01 * scale - curHeight, 0),
                              refpt.Convert3D(0.5 * scale, -1 * scale - curHeight, 0)
                             )
                            { Color = Color.FromColorIndex(ColorMethod.ByAci, 4), Layer = "细线", };

                            modelSpace.AppendEntity(Array);
                            tr.AddNewlyCreatedDBObject(Array, true);
                        }
                        L = new Line(refpt.Convert3D(0, -height - (1 + length) * scale, 0), refpt.Convert3D(0, 0, 0))
                        { Color = Color.FromColorIndex(ColorMethod.ByAci, 4), Layer = "细线", };
                        modelSpace.AppendEntity(L);
                        tr.AddNewlyCreatedDBObject(L, true);
                        if(leftLength>0)
                        {
                            L = new Line(refpt.Convert3D(leftLength, -height - (1 + length) * scale, 0), refpt.Convert3D(0, -height - (1 + length) * scale, 0))
                            { Color = Color.FromColorIndex(ColorMethod.ByAci, 4), Layer = "细线", };
                            modelSpace.AppendEntity(L);
                            tr.AddNewlyCreatedDBObject(L, true);
                            PositionPoint = refpt.Convert3D(leftLength +cR * scale, -height - (1 + length) * scale , 0);
                        }
                        else
                           PositionPoint = refpt.Convert3D(0, -height - (1 + length) * scale - cR * scale, 0);
                        break;
                    default:  //右
                        refpt = refpt.Convert3D(width, 0);
                        for (int i = 0; i < topSp.Count; i++)
                        {
                            Array = new Solid(
                             refpt.Convert3D(0 - curWidth, 0, 0),
                             refpt.Convert3D(-0.01 * scale - curWidth, 0, 0),
                              refpt.Convert3D(-1 * scale - curWidth, 0.5 * scale, 0)
                             )
                            { Color = Color.FromColorIndex(ColorMethod.ByAci, 4), Layer = "细线", };
                            modelSpace.AppendEntity(Array);
                            tr.AddNewlyCreatedDBObject(Array, true);
                            curWidth += topSp[topSp.Count - 1 - i];
                        }
                        L = new Line(refpt.Convert3D(-width - (1 + length) * scale, 0, 0), refpt.Convert3D(0, 0, 0))
                        { Color = Color.FromColorIndex(ColorMethod.ByAci, 4), Layer = "细线", };
                        modelSpace.AppendEntity(L);
                        tr.AddNewlyCreatedDBObject(L, true);
                        PositionPoint = refpt.Convert3D(-width - (1 + length) * scale - cR * scale, 0, 0);
                        break;
                }
                ext = ext.Add(new Extents2d(Array.Bounds.Value.MinPoint.Convert2D(), Array.Bounds.Value.MaxPoint.Convert2D()));
                ext = ext.Add(new Extents2d(L.Bounds.Value.MinPoint.Convert2D(), L.Bounds.Value.MaxPoint.Convert2D()));
                txt.TextString = textstring.ToString();
                txt.Height = 2.5 * scale;
                txt.Position = PositionPoint.Convert3D();
                txt.HorizontalMode = TextHorizontalMode.TextCenter;
                txt.VerticalMode = TextVerticalMode.TextVerticalMid;
                txt.AlignmentPoint = PositionPoint.Convert3D();
                txt.TextStyleId = st[Extensions.curFont];
                txt.Layer = "标注";
                txt.ColorIndex = 4;
                txt.WidthFactor = 0.8;

                C2 = new Circle(PositionPoint.Convert3D(), Vector3d.ZAxis, cR * scale);
                C2.Layer = "标注";
                C2.ColorIndex = 4;
                modelSpace.AppendEntity(txt);
                tr.AddNewlyCreatedDBObject(txt, true);
                modelSpace.AppendEntity(C2);
                tr.AddNewlyCreatedDBObject(C2, true);
                ext = ext.Add(new Extents2d(txt.Bounds.Value.MinPoint.Convert2D(), txt.Bounds.Value.MaxPoint.Convert2D()));
                ext = ext.Add(new Extents2d(C2.Bounds.Value.MinPoint.Convert2D(), C2.Bounds.Value.MaxPoint.Convert2D()));
                tr.Commit();
            }
        }

        public static void CreateBreakLine(Database db,  ref Extents2d ext ,Point2d stPoint, Point2d endPoint, double scale = 20)
        {
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder;
                recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                #region
                Point2d centerPt = GeTools.MidPoint(stPoint.Convert3D(), endPoint.Convert3D()).Convert2D();
                //画线
                Polyline line = new Polyline() { Closed = false, Layer = "细线",ColorIndex=1 };//定义不封闭的Polyline 平面虚线
                if (stPoint.Y > endPoint.Y && stPoint.X == endPoint.X)
                {
                    line.AddVertexAt(0, stPoint, 0, 0, 0);
                    line.AddVertexAt(1, centerPt.Convert2D(0, 1.7941*scale*0.05), 0, 0, 0);
                    line.AddVertexAt(2, centerPt.Convert2D(-2.4148 * scale * 0.05, 1.147 * scale * 0.05), 0, 0, 0);
                    line.AddVertexAt(3, centerPt, 0, 0, 0);
                    line.AddVertexAt(4, centerPt.Convert2D(2.4148 * scale * 0.05, -1.147 * scale * 0.05), 0, 0, 0);
                    line.AddVertexAt(5, centerPt.Convert2D(0, -1.7941 *scale * 0.05), 0, 0, 0);
                    line.AddVertexAt(6, endPoint, 0, 0, 0);
                }
                else if (stPoint.Y <= endPoint.Y && stPoint.X == endPoint.X)
                {
                    line.AddVertexAt(0, endPoint, 0, 0, 0);
                    line.AddVertexAt(1, centerPt.Convert2D(0, 1.7941 * scale * 0.05), 0, 0, 0);
                    line.AddVertexAt(2, centerPt.Convert2D(-2.4148 * scale * 0.05, 1.147 * scale * 0.05), 0, 0, 0);
                    line.AddVertexAt(3, centerPt, 0, 0, 0);
                    line.AddVertexAt(4, centerPt.Convert2D(2.4148 * scale * 0.05, -1.147 * scale * 0.05), 0, 0, 0);
                    line.AddVertexAt(5, centerPt.Convert2D(0, -1.7941 * scale * 0.05), 0, 0, 0);
                    line.AddVertexAt(6, stPoint, 0, 0, 0);
                }

                if (stPoint.X > endPoint.X && stPoint.Y == endPoint.Y)
                {
                    line.AddVertexAt(0, stPoint, 0, 0, 0);
                    line.AddVertexAt(1, centerPt.Convert2D(1.7941 * scale * 0.05, 0), 0, 0, 0);
                    line.AddVertexAt(2, centerPt.Convert2D(1.147 * scale * 0.05, -2.4148 * scale * 0.05), 0, 0, 0);
                    line.AddVertexAt(3, centerPt, 0, 0, 0);
                    line.AddVertexAt(4, centerPt.Convert2D(-1.147 * scale * 0.05, 2.4148 * scale * 0.05), 0, 0, 0);
                    line.AddVertexAt(5, centerPt.Convert2D(-1.7941 * scale * 0.05, 0), 0, 0, 0);
                    line.AddVertexAt(6, endPoint, 0, 0, 0);
                }
                else if (stPoint.X <= endPoint.X && stPoint.Y == endPoint.Y)
                {
                    line.AddVertexAt(0, endPoint, 0, 0, 0);
                    line.AddVertexAt(1, centerPt.Convert2D(1.7941 * scale * 0.05, 0), 0, 0, 0);
                    line.AddVertexAt(2, centerPt.Convert2D(1.147 * scale * 0.05, -2.4148 * scale * 0.05), 0, 0, 0);
                    line.AddVertexAt(3, centerPt, 0, 0, 0);
                    line.AddVertexAt(4, centerPt.Convert2D(-1.147 * scale * 0.05, 2.4148 * scale * 0.05), 0, 0, 0);
                    line.AddVertexAt(5, centerPt.Convert2D(-1.7941 * scale * 0.05, 0), 0, 0, 0);
                    line.AddVertexAt(6, stPoint, 0, 0, 0);
                }
                recorder.AppendEntity(line);
                tr.AddNewlyCreatedDBObject(line, true);

                ext = ext.Add(new Extents2d(line.Bounds.Value.MinPoint.Convert2D(), line.Bounds.Value.MaxPoint.Convert2D()));

                #endregion
                tr.Commit();
            }
        }

        public static void CreateUpperAndDownBreakLine(Database db, ref Extents2d ext, Point2d stPoint, Point2d endPoint,double scale=20)
        {
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder;
                recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                #region
                Point2d centerPt = GeTools.MidPoint(stPoint.Convert3D(), endPoint.Convert3D()).Convert2D();
                //画线
                Polyline line = new Polyline() { Closed = false, Layer = "细线", };//定义不封闭的Polyline 平面虚线
                if (stPoint.X > endPoint.X)
                {
                    line.AddVertexAt(0, stPoint, 0, 0, 0);
                    line.AddVertexAt(1, centerPt.Convert2D(1.7941 * scale, 0), 0, 0, 0);
                    line.AddVertexAt(2, centerPt.Convert2D(1.147 * scale, -2.4148 * scale), 0, 0, 0);
                    line.AddVertexAt(3, centerPt, 0, 0, 0);
                    line.AddVertexAt(4, centerPt.Convert2D(-1.147 * scale, 2.4148 * scale), 0, 0, 0);
                    line.AddVertexAt(5, centerPt.Convert2D(-1.7941 * scale, 0), 0, 0, 0);
                    line.AddVertexAt(6, endPoint, 0, 0, 0);
                }
                else
                {
                    line.AddVertexAt(0, endPoint, 0, 0, 0);
                    line.AddVertexAt(1, centerPt.Convert2D(1.7941 * scale, 0), 0, 0, 0);
                    line.AddVertexAt(2, centerPt.Convert2D(1.147 * scale, -2.4148 * scale), 0, 0, 0);
                    line.AddVertexAt(3, centerPt, 0, 0, 0);
                    line.AddVertexAt(4, centerPt.Convert2D(-1.147 * scale, 2.4148 * scale), 0, 0, 0);
                    line.AddVertexAt(5, centerPt.Convert2D(-1.7941 * scale, 0), 0, 0, 0);
                    line.AddVertexAt(6, stPoint, 0, 0, 0);
                }
                recorder.AppendEntity(line);
                tr.AddNewlyCreatedDBObject(line, true);

                ext = ext.Add(new Extents2d(line.Bounds.Value.MinPoint.Convert2D(), line.Bounds.Value.MaxPoint.Convert2D()));

                #endregion
                tr.Commit();
            }
        }

        public static void CreateBreakLineDim(Database db, ref Extents2d ext, Point2d stPoint, Point2d endPoint, string T1, string T2, string T3, int T4,double scale,double topLineWidth=0, string tstyle ="En")
        {
            tstyle = Extensions.curFont;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder;
                recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                #region
                Point2d centerPt = GeTools.MidPoint(stPoint.Convert3D(), endPoint.Convert3D()).Convert2D();
                Point2d threeDivPt ; 
                //画线
                Polyline line = new Polyline() { Closed = false, Layer = "细线", };//定义不封闭的Polyline 平面虚线
                Polyline line1 = new Polyline() { Closed = false, Layer = "细线", };
                if (stPoint.Y > endPoint.Y)
                {
                    line.AddVertexAt(0, stPoint, 0, 0, 0);
                    line.AddVertexAt(1, centerPt.Convert2D(0, 1.7941 * scale), 0, 0, 0);
                    line.AddVertexAt(2, centerPt.Convert2D(-2.4148 * scale, 1.147 * scale), 0, 0, 0);
                    line.AddVertexAt(3, centerPt, 0, 0, 0);
                    line.AddVertexAt(4, centerPt.Convert2D(2.4148 * scale, -1.147 * scale), 0, 0, 0);
                    line.AddVertexAt(5, centerPt.Convert2D(0, -1.7941 * scale), 0, 0, 0);
                    line.AddVertexAt(6, endPoint, 0, 0, 0);
                    threeDivPt = new Point2d((stPoint.X * 2 / 3.0 + endPoint.X / 3.0),
                                       (stPoint.Y * 2 / 3.0 + endPoint.Y / 3.0) );

                    line1.AddVertexAt(0, stPoint, 0, 0, 0);
                    line1.AddVertexAt(1, stPoint.Convert2D(topLineWidth, 0), 0, 0, 0);
                }
                else
                {
                    line.AddVertexAt(0, endPoint, 0, 0, 0);
                    line.AddVertexAt(1, centerPt.Convert2D(1.7941 * scale, 0), 0, 0, 0);
                    line.AddVertexAt(2, centerPt.Convert2D(1.147 * scale, -2.4148 * scale), 0, 0, 0);
                    line.AddVertexAt(3, centerPt, 0, 0, 0);
                    line.AddVertexAt(4, centerPt.Convert2D(-1.147 * scale, 2.4148 * scale), 0, 0, 0);
                    line.AddVertexAt(5, centerPt.Convert2D(-1.7941 * scale, 0), 0, 0, 0);
                    line.AddVertexAt(6, stPoint, 0, 0, 0);
                    threeDivPt = new Point2d((stPoint.X / 3.0 + endPoint.X * 2 / 3.0),
                                       (stPoint.Y / 3.0 + endPoint.Y * 2 / 3.0));

                    line1.AddVertexAt(0, endPoint, 0, 0, 0);
                    line1.AddVertexAt(1, endPoint.Convert2D(topLineWidth, 0), 0, 0, 0);
                }
                recorder.AppendEntity(line);
                tr.AddNewlyCreatedDBObject(line, true);
                recorder.AppendEntity(line1);
                tr.AddNewlyCreatedDBObject(line1, true);

                ext = ext.Add(new Extents2d(line.Bounds.Value.MinPoint.Convert2D(), line.Bounds.Value.MaxPoint.Convert2D()));
                ext = ext.Add(new Extents2d(line1.Bounds.Value.MinPoint.Convert2D(), line1.Bounds.Value.MaxPoint.Convert2D()));

                TextPloter.PlotText(db, ref ext, TextPloter.eTxtLocation.E_BOTTOM, centerPt.Convert2D(-2.5*scale,-20), T1, scale, tstyle, GeTools.DegreeToRadian(90));
                DimPloter.CreateLeadWire(db, ref ext, threeDivPt.Convert3D(), T2, T3, T4, Extensions.curFont, scale);
                #endregion
                tr.Commit();
            }
        }

        /// <summary>
        /// 绘制钢筋模型
        /// </summary>
        /// <param name="db"></param>
        /// <param name="T1">左边参数</param>
        /// <param name="T2">右边参数</param>
        /// <param name="T3">横线参数</param>
        /// <param name="T4">引线上部参数</param>
        /// <param name="T5">引线下部参数</param>
        /// <param name="T6">引线圆内参数</param>
        /// <param name="hLeft">左边线长</param>
        /// <param name="hRight">右边线长</param>
        /// <param name="width">横线长度</param>
        /// <param name="Rotation">旋转家督</param>
        /// <param name="scale">比例</param>
        /// <returns></returns>
        public static void CreateRebarModel(Database db, ref Extents2d ext,Point2d startPoint, string T1, string T2, string T3, string T4, string T5,
            int T6, double hLeft, double hRight, double width, double Rotation, double scale = 100)
        {
            DBObjectCollection res = new DBObjectCollection();
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                #region 绘制钢筋和引线
                // 绘制钢筋
                Polyline rebarLine = new Polyline() { Closed = false, Layer = "细线", };
                Point2d p1 = startPoint.Convert2D(-width / 2); ;
                Point2d p2 = p1.Convert2D(0, -hLeft);
                Point2d p3 = startPoint.Convert2D(width / 2);
                Point2d p4 = p3.Convert2D(0, -hRight);
                rebarLine.AddVertexAt(0, p4, 0, 0, 0);
                rebarLine.AddVertexAt(1, p3, 0, 0, 0);
                rebarLine.AddVertexAt(2, p1, 0, 0, 0);
                rebarLine.AddVertexAt(3, p2, 0, 0, 0);
                res.Add(rebarLine);
                ext = ext.Add(new Extents2d(rebarLine.Bounds.Value.MinPoint.Convert2D(), rebarLine.Bounds.Value.MaxPoint.Convert2D()));

                // 文字标注
                //Point2d pt1 = p1.Convert2D(0, -hLeft / 2);
                //DBObjectCollection res1 = TextPloter.PlotText(db, ref ext, TextPloter.eTxtLocation.E_LEFT, pt1, T1, scale, Extensions.curFont, GeTools.DegreeToRadian(90));

                //Point2d pt2 = p3.Convert2D(0, -hRight / 2);
                //DBObjectCollection res2 = TextPloter.PlotText(db, ref ext, TextPloter.eTxtLocation.E_RIGHT, pt2, T2, scale, Extensions.curFont, GeTools.DegreeToRadian(90));

                // 横线文字
                //Point2d pt3 = startPoint.Convert2D();
                //DBObjectCollection res3 = TextPloter.PlotText(db, ref ext, TextPloter.eTxtLocation.E_TOP, pt3, T3, scale, Extensions.curFont, GeTools.DegreeToRadian(0));

                // 引线位置
                Point2d wirePt = p3.Convert2D(-width / 3, 0);
                if (Rotation == 0 || Rotation == 360)
                {
                    wirePt = p2.Convert2D();
                }
                else if (Rotation == 90)
                {
                    wirePt = startPoint.Convert2D();
                }
                else if (Rotation == 180)
                {
                    wirePt = startPoint.Convert2D();
                }
                else if (Rotation == 270)
                {
                    wirePt = startPoint.Convert2D(0,width/4);
                }
                // 钢筋引线
                DimPloter.RebarWire(db, ref ext, wirePt, T4, T5, T6,
                   0, Extensions.curFont, scale);

                var TX1 = Matrix3d.Rotation(GeTools.DegreeToRadian(Rotation), Vector3d.ZAxis, startPoint.Convert3D());
                foreach (DBObject item in res)
                {
                    Entity pr = (Entity)item;
                    pr.TransformBy(TX1);
                }

                foreach (DBObject drawitem in res)
                {
                    recorder.AppendEntity((Entity)drawitem);
                    tr.AddNewlyCreatedDBObject(drawitem, true);
                }
                #endregion

                #region 绘制文字标注
                // 旋转文字使符合阅读习惯
                double txtRotation = Rotation;
                Point2d txtPt = startPoint;
                DBObjectCollection res1 = new DBObjectCollection();
                DBObjectCollection res2 = new DBObjectCollection();
                DBObjectCollection res3 = new DBObjectCollection();
                Point2d pt1 = Point2d.Origin;
                Point2d pt2 = Point2d.Origin;
                Point2d pt3 = Point2d.Origin;
                double txtRota1 = 0;
                double txtRota2 = 0;
                double txtRota3 = 0;
                TextPloter.eTxtLocation elocal1 = TextPloter.eTxtLocation.E_TOP;
                TextPloter.eTxtLocation elocal2 = TextPloter.eTxtLocation.E_TOP;
                TextPloter.eTxtLocation elocal3 = TextPloter.eTxtLocation.E_TOP;
                string txt1 = T1;
                string txt2 = T2;
                string txt3 = T3;

                if (Rotation == 0 || Rotation == 360)
                {
                    // 文字标注
                    pt1 = p1.Convert2D(-scale, -hLeft / 2);
                    pt2 = p3.Convert2D(scale, -hRight / 2);

                    // 横线文字
                    pt3 = startPoint.Convert2D(0, scale);
                    elocal1 = TextPloter.eTxtLocation.E_LEFT;
                    elocal2 = TextPloter.eTxtLocation.E_RIGHT;
                    elocal3 = TextPloter.eTxtLocation.E_TOP;
                    txtRota1 = 90;
                    txtRota2 = 90;
                    txtRota3 = 0;

                    txt1 = T1;
                    txt2 = T2;
                    txt3 = T3;
                }
                else if (Rotation == 90)
                {
                    // 文字标注
                    pt1 = startPoint.Convert2D(hRight/2, width / 2+ scale);
                    pt2 = startPoint.Convert2D(hLeft/2, -width / 2- scale);

                    // 横线文字
                    pt3 = startPoint.Convert2D(-scale);

                    elocal1 = TextPloter.eTxtLocation.E_TOP;
                    elocal2 = TextPloter.eTxtLocation.E_BOTTOM;
                    elocal3 = TextPloter.eTxtLocation.E_LEFT;
                    txtRota1 = 0;
                    txtRota2 = 0;
                    txtRota3 = 90;

                    txt1 = T2;
                    txt2 = T1;
                    txt3 = T3;
                }
                else if (Rotation == 180)
                {
                    // 文字标注
                    pt1 = startPoint.Convert2D(-width/2 - scale, hRight / 2);
                    pt2 = startPoint.Convert2D(width / 2+ scale, hLeft / 2);

                    // 横线文字
                    pt3 = startPoint.Convert2D(0,-scale);

                    elocal1 = TextPloter.eTxtLocation.E_LEFT;
                    elocal2 = TextPloter.eTxtLocation.E_RIGHT;
                    elocal3 = TextPloter.eTxtLocation.E_BOTTOM;
                    txtRota1 = 90;
                    txtRota2 = 90;
                    txtRota3 = 0;

                    txt1 = T2;
                    txt2 = T1;
                    txt3 = T3;
                }
                else if (Rotation == 270)
                {
                    // 文字标注
                    pt1 = startPoint.Convert2D(-hRight / 2, -width / 2 -scale*4);
                    pt2 = startPoint.Convert2D(-hLeft / 2, width / 2+scale);

                    // 横线文字
                    pt3 = startPoint.Convert2D(scale*4);

                    elocal1 = TextPloter.eTxtLocation.E_TOP;
                    elocal2 = TextPloter.eTxtLocation.E_RIGHT;
                    elocal3 = TextPloter.eTxtLocation.E_BOTTOM;

                    txtRota1 = 0;
                    txtRota2 = 0;
                    txtRota3 = 90;

                    txt1 = T2;
                    txt2 = T1;
                    txt3 = T3;
                }

                // 文字标注
                res1 = TextPloter.PlotText(db, ref ext, elocal1, pt1, txt1, scale, Extensions.curFont, GeTools.DegreeToRadian(txtRota1));
                res2 = TextPloter.PlotText(db, ref ext, elocal2, pt2, txt2, scale, Extensions.curFont, GeTools.DegreeToRadian(txtRota2));

                // 横线文字
                res3 = TextPloter.PlotText(db, ref ext, elocal3, pt3, txt3, scale, Extensions.curFont, GeTools.DegreeToRadian(txtRota3));
                #endregion
                tr.Commit();
            }
        }

        /// <summary>
        /// 实心圆
        /// </summary>
        /// <param name="pt">圆点</param>
        /// <param name="radius">半径</param>
        /// <returns></returns>
        public static void CreateSolidCircle(Database db, ref Extents2d ext,Point3d pt, double radius)
        {
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                Circle circle = new Circle(pt, Vector3d.ZAxis, radius) { Layer = "细线",ColorIndex=6 };
                circle.SetDatabaseDefaults();//默认参数
                recorder.AppendEntity(circle);
                tr.AddNewlyCreatedDBObject(circle, true);
                ext = ext.Add(new Extents2d(circle.Bounds.Value.MinPoint.Convert2D(), circle.Bounds.Value.MaxPoint.Convert2D()));

                // 添加圆到一个 ObjectID 数组中去 
                ObjectIdCollection acObjIdColl = new ObjectIdCollection();
                acObjIdColl.Add(circle.ObjectId);

                // 创建图案填充对象并添加到块表记录中   
                Hatch hatch = new Hatch();
                hatch.ColorIndex = 6;
                recorder.AppendEntity(hatch);
                tr.AddNewlyCreatedDBObject(hatch, true);
                hatch.SetDatabaseDefaults();
                //hatch.SetHatchPattern(HatchPatternType.PreDefined, "ANSI31");//ANSI31为金属剖面线
                hatch.SetHatchPattern(HatchPatternType.PreDefined, "SOLID"); //设置填充图案
                hatch.Associative = true;
                hatch.AppendLoop(HatchLoopTypes.Outermost, acObjIdColl);
                hatch.EvaluateHatch(true);

                tr.Commit();
            }
        }

        /// <summary>
        /// 钢筋笼立面
        /// </summary>
        /// <param name="db"></param>
        /// <param name="ext"></param>
        /// <param name="pt">绘制起点</param>
        /// <param name="radius1">最外侧圆半径</param>
        /// <param name="radius2">中间圆半径</param>
        /// <param name="radius3">最内侧圆半径param>
        /// <param name="rebarNum">圆环内钢筋数量</param>
        /// <param name="T1"></param>
        /// <param name="T2"></param>
        /// <param name="T3"></param>
        /// <param name="scale"></param>
        public static void CreateFacadeReinforcementCage(Database db, ref Extents2d ext,
            Point3d pt, double radius1, double radius2, double radius3,double rebarNum,
            string T1, string T2, string T3, double scale,double Radia=30)
        {
            DBObjectCollection res = new DBObjectCollection();
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                #region 圆环
                // 外圆
                Circle exCircle = new Circle(pt.Add(new Vector3d(radius1, 0, 0)), Vector3d.ZAxis, radius1){ Layer = "粗线" };
                res.Add(exCircle);
                ext = ext.Add(new Extents2d(exCircle.Bounds.Value.MinPoint.Convert2D(), exCircle.Bounds.Value.MaxPoint.Convert2D()));

                // 中间圆
                Circle circle = new Circle(pt.Add(new Vector3d(radius1, 0, 0)), Vector3d.ZAxis, radius2) { Layer = "粗线" };
                res.Add(circle);
                ext = ext.Add(new Extents2d(circle.Bounds.Value.MinPoint.Convert2D(), circle.Bounds.Value.MaxPoint.Convert2D()));

                // 内圆
                Circle innerCircle = new Circle(pt.Add(new Vector3d(radius1, 0, 0)), Vector3d.ZAxis, radius3){ Layer = "粗线" };
                ext = ext.Add(new Extents2d(innerCircle.Bounds.Value.MinPoint.Convert2D(), innerCircle.Bounds.Value.MaxPoint.Convert2D()));
                res.Add(innerCircle);

                // 钢筋半径
                double reBarRadius = Radia ;

                // 绘制环内圆点
                double height = 0;
                double width = 0;
                double radiusInterval = radius2 - reBarRadius;

                // 圆点中心坐标
                List<Point3d> list = new List<Point3d>();
                #region 绘制环内圆点
                for (int i = 0; i < rebarNum; ++i)
                {
                    // 计算圆点
                    Point3d center = pt.Add(new Vector3d(2 * radius1 - reBarRadius, 0, 0));

                    double angle = 360 / rebarNum * i;

                    if (angle > 0 && angle < 90)
                    {
                        angle = GeTools.DegreeToRadian(angle);
                        height = Math.Abs(radiusInterval * Math.Sin(angle));
                        width = -Math.Abs(radiusInterval * Math.Cos(angle));
                    }
                    else if (angle > 90 && angle < 180)
                    {
                        angle = GeTools.DegreeToRadian(180 - angle);
                        height = Math.Abs(radiusInterval * Math.Sin(angle));
                        width = Math.Abs(radiusInterval * Math.Cos(angle));
                    }
                    else if (angle > 180 && angle < 270)
                    {
                        angle = GeTools.DegreeToRadian(270 - angle);
                        height = -Math.Abs(radiusInterval * Math.Cos(angle));
                        width = Math.Abs(radiusInterval * Math.Sin(angle));
                    }
                    else if (angle > 270 && angle < 360)
                    {
                        angle = GeTools.DegreeToRadian(360 - angle);
                        height = -Math.Abs(radiusInterval * Math.Sin(angle));
                        width = -Math.Abs(radiusInterval * Math.Cos(angle));
                    }
                    else if (angle == 0 || angle == 360)
                    {
                        height = -radiusInterval * Math.Sin(0);
                        width = -radiusInterval * Math.Cos(0);
                    }
                    else if (angle == 90)
                    {
                        height = radiusInterval * Math.Cos(0);
                        width = radiusInterval * Math.Sin(0);
                    }
                    else if (angle == 180)
                    {
                        angle = 360 - angle;
                        height = radiusInterval * Math.Sin(0);
                        width = radiusInterval * Math.Cos(0);
                    }
                    else if (angle == 270)
                    {
                        angle = 360 - angle;
                        height = -radiusInterval * Math.Cos(0);
                        width = radiusInterval * Math.Sin(0);
                    }

                    center = pt.Add(new Vector3d(radius1 + width, height, 0));
                    list.Add(center);
                    PolylinePloter.CreateSolidCircle(db, ref ext, center, reBarRadius);
                }
                #endregion
                #endregion

                #region 标记
                // 圆心坐标
                Point3d circleCenter = pt.Convert3D(radius1);

                // 外圆半径标记
                DBObjectCollection res1 =  DimPloter.ArrowLine(db,ref ext, ArrowDirection.East, circleCenter, radius1,scale);
                DBObjectCollection res2 = TextPloter.PlotText(db, ref ext, TextPloter.eTxtLocation.E_TOP, 
                    circleCenter.Convert2D(radius1 / 2,5), string.Format("R{0}", radius1), scale, Extensions.curFont,
                    GeTools.DegreeToRadian(0));
                var TX1 = Matrix3d.Rotation(GeTools.DegreeToRadian(30), Vector3d.ZAxis, circleCenter.Convert3D());
                foreach (DBObject item in res1)
                {
                    Entity pr = (Entity)item;
                    pr.TransformBy(TX1);
                }
                foreach (DBObject item in res2)
                {
                    Entity pr = (Entity)item;
                    pr.TransformBy(TX1);
                }

                // 中间圆半径标记
                res1 = DimPloter.ArrowLine(db, ref ext, ArrowDirection.East, circleCenter, radius2, scale);
                res2 = TextPloter.PlotText(db, ref ext, TextPloter.eTxtLocation.E_TOP,
                    circleCenter.Convert2D(radius2 / 2, 5), string.Format("R{0}", radius2), scale, Extensions.curFont,
                    GeTools.DegreeToRadian(0));
                TX1 = Matrix3d.Rotation(GeTools.DegreeToRadian(-30), Vector3d.ZAxis, circleCenter.Convert3D());
                foreach (DBObject item in res1)
                {
                    Entity pr = (Entity)item;
                    pr.TransformBy(TX1);
                }
                foreach (DBObject item in res2)
                {
                    Entity pr = (Entity)item;
                    pr.TransformBy(TX1);
                }

                // 内圆半径标记
                res1 = DimPloter.ArrowLine(db, ref ext, ArrowDirection.West, circleCenter, radius3, scale);
                res2 = TextPloter.PlotText(db, ref ext, TextPloter.eTxtLocation.E_TOP,
                    circleCenter.Convert2D(-radius3 / 2, 5), string.Format("R{0}", radius3), scale, Extensions.curFont,
                    GeTools.DegreeToRadian(0));
                TX1 = Matrix3d.Rotation(GeTools.DegreeToRadian(15), Vector3d.ZAxis, circleCenter.Convert3D());
                foreach (DBObject item in res1)
                {
                    Entity pr = (Entity)item;
                    pr.TransformBy(TX1);
                }
                foreach (DBObject item in res2)
                {
                    Entity pr = (Entity)item;
                    pr.TransformBy(TX1);
                }
                #endregion

                #region 标注
                if(list != null && list.Count > 0)
                {
                    Point3d p1, p2, p3=new Point3d(),p4, p5;
                    double offsetX = radius1 / 2;
                    double offsetY = radius1 / 2;
                    int index = list.Count / 4 + 1;
                    if (index < list.Count)
                    {
                        p1 = list[index];
                        p3 = p1.Convert3D(-offsetX/2,-offsetY);
                        
                        Polyline Line1 = new Polyline() { Closed = false, Layer = "细线" };
                        Line1.AddVertexAt(0, p1.Convert2D(),0,0,0);
                        Line1.AddVertexAt(0, p3.Convert2D(), 0, 0, 0);
                        ext = ext.Add(new Extents2d(Line1.Bounds.Value.MinPoint.Convert2D(), Line1.Bounds.Value.MaxPoint.Convert2D()));
                        res.Add(Line1);
                    }

                    if (index+1 < list.Count)
                    {
                        p2 = list[index+1];
                        p4 =new Point3d(p2.X - offsetX / 2,p3.Y,0);
                        Polyline Line2 = new Polyline() { Closed = false, Layer = "细线" };
                        Line2.AddVertexAt(0, p2.Convert2D(), 0, 0, 0);
                        Line2.AddVertexAt(0, p4.Convert2D(), 0, 0, 0);
                        ext = ext.Add(new Extents2d(Line2.Bounds.Value.MinPoint.Convert2D(), Line2.Bounds.Value.MaxPoint.Convert2D()));
                        res.Add(Line2);

                        p5 = p3.Convert3D(-offsetX*0.5);
                        Line2 = new Polyline() { Closed = false, Layer = "细线" };
                        Line2.AddVertexAt(0, p4.Convert2D(), 0, 0, 0);
                        Line2.AddVertexAt(0, p5.Convert2D(), 0, 0, 0);
                        ext = ext.Add(new Extents2d(Line2.Bounds.Value.MinPoint.Convert2D(), Line2.Bounds.Value.MaxPoint.Convert2D()));
                        res.Add(Line2);

                        // 圆形标记
                        DimPloter.CircularMark(db, ref ext, p5.Convert3D(-2.5*scale*2), "1", Extensions.curFont, scale);
                    }

                    // 圆环标记
                    // 外圆
                    double valueX = radius1 * Math.Cos(GeTools.DegreeToRadian(45));
                    Point3d pt1 = circleCenter.Convert3D(radius1);
                    DimPloter.CreateHookLineMark(db, ref ext, pt1, "7", (radius1-radius2)*10, scale,0);

                    // 中间圆
                    valueX = radius2 * Math.Cos(GeTools.DegreeToRadian(45));
                    pt1 = circleCenter.Convert3D(valueX, -valueX);
                    DimPloter.CreateHookLineMark(db, ref ext, pt1, "5", (radius1 - radius2) * 10, scale,-45);

                    //// 内圆
                    valueX = radius3 * Math.Cos(GeTools.DegreeToRadian(225));
                    pt1 = circleCenter.Convert3D(valueX, valueX);
                    DimPloter.CreateHookLineMark(db, ref ext, pt1, "3", (radius1 - radius2) * 10, scale,225);
                }
                #endregion

                #region 声测管
                double soundPipeRadius = reBarRadius * 2;
                // 声测管布控
                int soundPipeNum = radius1*2 / (800) <= 1 ? 2 : 2 + (int)(radius1*2/ (800));
                // 声空管距圆心距离一致
                height = 0;
                width = 0;
                double thick = 20;
                List<Point3d> soundPipelist = new List<Point3d>();
                radiusInterval = radius3 - soundPipeRadius - thick;
                for (int i = 0; i < soundPipeNum; ++i)
                {
                    Point3d center = pt;
                    double angle = 360 / soundPipeNum * i;
                    if (angle > 0 && angle < 90)
                    {
                        angle = GeTools.DegreeToRadian(angle);
                        height = Math.Abs(radiusInterval * Math.Sin(angle));
                        width = -Math.Abs(radiusInterval * Math.Cos(angle));
                    }
                    else if (angle > 90 && angle < 180)
                    {
                        angle = GeTools.DegreeToRadian(180 - angle);
                        height = Math.Abs(radiusInterval * Math.Sin(angle));
                        width = Math.Abs(radiusInterval * Math.Cos(angle));
                    }
                    else if (angle > 180 && angle < 270)
                    {
                        angle = GeTools.DegreeToRadian(270 - angle);
                        height = -Math.Abs(radiusInterval * Math.Cos(angle));
                        width = Math.Abs(radiusInterval * Math.Sin(angle));
                    }
                    else if (angle > 270 && angle < 360)
                    {
                        angle = GeTools.DegreeToRadian(360 - angle);
                        height = -Math.Abs(radiusInterval * Math.Sin(angle));
                        width = -Math.Abs(radiusInterval * Math.Cos(angle));
                    }
                    else if (angle == 0 || angle == 360)
                    {
                        height = -radiusInterval * Math.Sin(0);
                        width = -radiusInterval * Math.Cos(0);
                    }
                    else if (angle == 90)
                    {
                        height = radiusInterval * Math.Cos(0);
                        width = radiusInterval * Math.Sin(0);
                    }
                    else if (angle == 180)
                    {
                        angle = 360 - angle;
                        height = radiusInterval * Math.Sin(0);
                        width = radiusInterval * Math.Cos(0);
                    }
                    else if (angle == 270)
                    {
                        angle = 360 - angle;
                        height = -radiusInterval * Math.Cos(0);
                        width = radiusInterval * Math.Sin(0);
                    }

                    center = pt.Add(new Vector3d(radius1 + width, height, 0));
                    soundPipelist.Add(center);
                }

                for (int i = 0; i < soundPipelist.Count; ++i)
                {
                    circle = new Circle(soundPipelist[i].Convert3D(), Vector3d.ZAxis, soundPipeRadius) { Layer = "粗线" };
                    res.Add(circle);
                    ext = ext.Add(new Extents2d(circle.Bounds.Value.MinPoint.Convert2D(), circle.Bounds.Value.MaxPoint.Convert2D()));
                }
                DimPloter.CreateLeadWireWithoutCircleMark(db, ref ext, soundPipelist[soundPipelist.Count - 1], "声测管", "", Extensions.curFont, scale);
                #endregion

                // 两点之间的间距标注
                double arg = Math.Atan(Math.Abs(list[3].Y - list[2].Y)/ Math.Abs(list[3].X - list[2].X));
                arg = GeTools.RadianToDegree(arg);
                RotatedDimension Dim2 = DimPloter.AddRotDim(db,ref ext,list[2].Convert3D(), list[3].Convert3D(), list[2].Convert3D(-5*scale,5*scale), scale, arg);
                //ext = ext.Add(new Extents2d(Dim2.Bounds.Value.MinPoint.Convert2D(), Dim2.Bounds.Value.MaxPoint.Convert2D()));
                res.Add(Dim2);

                foreach (DBObject drawitem in res)
                {
                    recorder.AppendEntity((Entity)drawitem);
                    tr.AddNewlyCreatedDBObject(drawitem, true);
                }

                tr.Commit();
                ext = ext.Add(new Extents2d(Dim2.Bounds.Value.MinPoint.Convert2D(), Dim2.Bounds.Value.MaxPoint.Convert2D()));
            }
        }

        public static void AddLine(Database db, ref Extents2d ext, Point3d stPoint, Point3d endPoint, string layer="粗线",int colorIndex=1,double scale=1)
        {         
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;

                Line line = new Line(stPoint, endPoint);
                line.Layer = layer;
                line.ColorIndex = colorIndex;
                line.LinetypeScale = scale;
                modelSpace.AppendEntity(line);
                tr.AddNewlyCreatedDBObject(line, true);
                ext = ext.Add(new Extents2d(line.Bounds.Value.MinPoint.Convert2D(), line.Bounds.Value.MaxPoint.Convert2D()));
                tr.Commit();
            }
        }

        public static void CreateLine(Database db, ref Extents2d ext, Point3d stPoint, Point3d endPoint, ref Line line, string layer = "粗线", int colorIndex = 1)
        {
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;

                line = new Line(stPoint, endPoint);
                line.Layer = layer;
                line.ColorIndex = colorIndex;
                modelSpace.AppendEntity(line);
                tr.AddNewlyCreatedDBObject(line, true);
                ext = ext.Add(new Extents2d(line.Bounds.Value.MinPoint.Convert2D(), line.Bounds.Value.MaxPoint.Convert2D()));
                tr.Commit();
            }
        }

        /// <summary>
        /// 绘制钢筋笼侧面图
        /// </summary>
        /// <param name="db"></param>
        /// <param name="ext"></param>
        /// <param name="pt"></param>
        /// <param name="pileHeight">柱子高度</param>
        /// <param name="radius">圆柱半径</param>
        /// <param name="rebarNum"></param>
        public static void CreateSideReinforcementCage(Database db, ref Extents2d ext, Point3d pt, double radius, 
            int rebarNum,double pileHeight, double rotation,string T1, string T2,string T3, double scale=100)
        {
            DBObjectCollection res = new DBObjectCollection();
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                // 布筋两边距弧线形边缘的距离
                double arcEdgeDeer = radius / 10;

                // 圆弧半径
                double arcRadius = radius+ arcEdgeDeer;

                // 横向钢筋的间隔
                double hSpace = radius / 10;

                //计算每根钢筋的起始坐标
                #region 计算每根钢筋的投影坐标
                double height = 0;
                double width = 0;

                List<Point3d> list = new List<Point3d>();
                list.Add(pt.Convert3D(arcEdgeDeer*scale));
                for (int i = 1; i < rebarNum; ++i)
                {
                    // 计算圆点
                    double angle = 360 / rebarNum * i;

                    if (angle > 0 && angle < 90)
                    {
                        angle = GeTools.DegreeToRadian(angle);
                        height = Math.Abs(radius  * Math.Sin(angle));
                        width = -Math.Abs(radius * Math.Cos(angle));
                    }
                    else if (angle > 90 && angle < 180)
                    {
                        angle = GeTools.DegreeToRadian(180 - angle);
                        height = Math.Abs(radius  * Math.Sin(angle));
                        width = Math.Abs(radius  * Math.Cos(angle));
                    }
                    else if (angle > 180 && angle < 270)
                    {
                        angle = GeTools.DegreeToRadian(270 - angle);
                        height = -Math.Abs(radius  * Math.Cos(angle));
                        width = Math.Abs(radius * Math.Sin(angle));
                    }
                    else if (angle > 270 && angle < 360)
                    {
                        angle = GeTools.DegreeToRadian(360 - angle);
                        height = -Math.Abs(radius * Math.Sin(angle));
                        width = -Math.Abs(radius  * Math.Cos(angle));
                    }
                    else if (angle == 0 || angle == 360)
                    {
                        height = -radius * Math.Sin(0);
                        width = -radius  * Math.Cos(0);
                    }
                    else if (angle == 90)
                    {
                        height = radius * Math.Cos(0);
                        width = radius  * Math.Sin(0);
                    }
                    else if (angle == 180)
                    {
                        angle = 360 - angle;
                        height = radius * Math.Sin(0);
                        width = radius * Math.Cos(0);
                    }
                    else if (angle == 270)
                    {
                        angle = 360 - angle;
                        height = -radius* Math.Cos(0);
                        width = radius * Math.Sin(0);
                    }

                    //Point3d center = pt.Add(new Vector3d(radius + width,0, 0));
                    Point3d center = pt.Convert3D((arcRadius+width)*scale);
                    list.Add(center);
                }

                list.Sort((a, b) => a.X.CompareTo(b.X));
                // 绘制钢筋投影

                // 绘制弧线
                double startAngle = 60;
                double arcAngle = 60;
                Arc arc1 = new Arc(pt.Convert3D(arcRadius/2*scale, -(arcRadius*Math.Cos(GeTools.DegreeToRadian(arcAngle/2))+pileHeight)*scale), 
                    arcRadius*scale, GeTools.DegreeToRadian(60), GeTools.DegreeToRadian(60+ arcAngle)) { Layer = "细线" };
                ext = ext.Add(new Extents2d(arc1.Bounds.Value.MinPoint.Convert2D(), arc1.Bounds.Value.MaxPoint.Convert2D()));
                res.Add(arc1);

                Arc arc2 = new Arc(pt.Convert3D(arcRadius/2*scale, -(pileHeight- arcRadius * Math.Cos(GeTools.DegreeToRadian(arcAngle / 2)))*scale),
                    arcRadius * scale, GeTools.DegreeToRadian(240), GeTools.DegreeToRadian(240+ arcAngle)) { Layer = "细线" };
                ext = ext.Add(new Extents2d(arc2.Bounds.Value.MinPoint.Convert2D(), arc2.Bounds.Value.MaxPoint.Convert2D()));
                res.Add(arc2);

                Arc arc3 = new Arc(pt.Convert3D((arcRadius + arcRadius / 2)*scale, -(pileHeight- arcRadius * Math.Cos(GeTools.DegreeToRadian(arcAngle / 2)))*scale), 
                    arcRadius * scale, GeTools.DegreeToRadian(240), GeTools.DegreeToRadian(240 + arcAngle)) { Layer = "细线" };
                ext = ext.Add(new Extents2d(arc3.Bounds.Value.MinPoint.Convert2D(), arc3.Bounds.Value.MaxPoint.Convert2D()));
                res.Add(arc3);

                List<Point3d> listBak = new List<Point3d>();
                Point3dCollection pts = new Point3dCollection();
                for (int i = 0; i < rebarNum; ++i)
                {
                    double cosValue = 0;
                    double angle = 0;
                    double sinValue = 0;
                    Polyline line = new Polyline() { Closed = false, Layer = "粗线" };
                    
                    // 计算垂直钢筋线与弧线的交点
                    if((list[i].X >= arc1.Center.X-arcRadius/2*scale) && list[i].X <= arc3.Center.X+arcRadius/2*scale)
                    {
                        if ((list[i].X >= arc1.Center.X - arcRadius / 2 * scale) && list[i].X <= arc1.Center.X + arcRadius / 2 * scale)
                        {
                            Line l1 = new Line(list[i].Convert3D(), list[i].Convert3D(0, pileHeight * 2 * scale));
                            pts.Clear();
                            l1.IntersectWith((Entity)arc1, Intersect.ExtendBoth, pts, IntPtr.Zero, IntPtr.Zero);
                            if (pts != null && pts.Count > 0)
                            {
                                if ((list[i].X >= arc1.Center.X - arcRadius / 2 * scale) && list[i].X <= arc1.Center.X)
                                {
                                    line.AddVertexAt(0, list[i].Convert2D(), 0, 0, 0);
                                    line.AddVertexAt(0, pts[1].Convert2D(), 0, 0, 0);
                                }
                                else if ((list[i].X >= arc1.Center.X) && list[i].X <= arc1.Center.X + arcRadius / 2 * scale)
                                {
                                    line.AddVertexAt(0, list[i].Convert2D(), 0, 0, 0);
                                    line.AddVertexAt(0, pts[0].Convert2D(), 0, 0, 0);
                                }
                            }
                            else
                            {
                                line.AddVertexAt(0, list[i].Convert2D(), 0, 0, 0);
                                line.AddVertexAt(0, list[i].Convert2D(0, -pileHeight * scale), 0, 0, 0);
                            }
                        }
                        if ((list[i].X >= arc1.Center.X + arcRadius / 2 * scale) && list[i].X <= arc3.Center.X + arcRadius / 2 * scale)
                        {
                            Line l1 = new Line(list[i].Convert3D(), list[i].Convert3D(0, pileHeight * 2 * scale));
                            pts.Clear();
                            l1.IntersectWith((Entity)arc3, Intersect.ExtendBoth, pts, IntPtr.Zero, IntPtr.Zero);
                            if (pts != null && pts.Count > 0)
                            {
                                if ((list[i].X >= arc1.Center.X + arcRadius / 2 * scale) && list[i].X <= arc3.Center.X)
                                {
                                    line.AddVertexAt(0, list[i].Convert2D(), 0, 0, 0);
                                    line.AddVertexAt(0, pts[0].Convert2D(), 0, 0, 0);
                                }
                                else if ((list[i].X >= arc3.Center.X) && list[i].X <= arc3.Center.X + arcRadius / 2 * scale)
                                {
                                    line.AddVertexAt(0, list[i].Convert2D(), 0, 0, 0);
                                    line.AddVertexAt(0, pts[1].Convert2D(), 0, 0, 0);
                                }
                            }
                            else
                            {
                                line.AddVertexAt(0, list[i].Convert2D(), 0, 0, 0);
                                line.AddVertexAt(0, list[i].Convert2D(0, -pileHeight * scale), 0, 0, 0);
                            }
                        }
                    }
                    if(line.Bounds != null)
                    {
                        ext = ext.Add(new Extents2d(line.Bounds.Value.MinPoint.Convert2D(), line.Bounds.Value.MaxPoint.Convert2D()));
                        res.Add(line);
                    }
                }

                // 计算横向钢筋线与弧线的交叉线
                double sinSide = 0;
                double sinAngle = 0;
                double cosSide = 0;

                // 横向钢筋的数量
                int hRebarNum = (int)(Math.Abs((list[0].Y - (arc3.Center.Y - arcRadius*scale))) / (hSpace*scale));
                for (int i = 0; i < hRebarNum; ++i)
                {
                    Polyline line2 = new Polyline() { Closed = false, Layer = "粗线" };
                    Polyline line3 = new Polyline() { Closed = false, Layer = "粗线" };
                    if ((pt.Y - hSpace *scale* (i + 1) >= arc3.Center.Y - arcRadius*scale) && (pt.Y - hSpace *scale* (i + 1) <= list[0].Y))
                    {
                        if(list[0].Y >= pt.Y - hSpace*scale*(i+1) && pt.Y - hSpace * scale * (i + 1) >= arc1.Center.Y+arcRadius*scale)
                        {
                            line2.AddVertexAt(0, list[0].Convert2D(-scale / 2, -hSpace * scale * (i + 1)), 0, 0, 0);
                            line2.AddVertexAt(0, list[list.Count - 1].Convert2D(scale / 2, -hSpace * scale * (i + 1)), 0, 0, 0);
                            ext = ext.Add(new Extents2d(line2.Bounds.Value.MinPoint.Convert2D(), line2.Bounds.Value.MaxPoint.Convert2D()));
                            res.Add(line2);
                        }
                        else if ((list[0].Y - hSpace * scale * (i + 1)) <= (arc1.Center.Y + arcRadius * scale) &&
                            (list[0].Y - hSpace * scale * (i + 1)) >= arc1.Center.Y + arcRadius * scale * Math.Cos(GeTools.DegreeToRadian(arcAngle / 2)))
                        {
                            //左边弧形交点计算
                            Line l1 = new Line(list[i].Convert3D(0, -hSpace * scale * (i + 1)), list[i].Convert3D(pileHeight * 2 * scale, -hSpace * scale * (i + 1)));
                            pts.Clear();
                            l1.IntersectWith((Entity)arc1, Intersect.ExtendBoth, pts, IntPtr.Zero, IntPtr.Zero);

                            if(pts == null || pts.Count == 0)
                            {
                                continue;
                            }
                            line2.AddVertexAt(0, list[0].Convert2D(-scale / 2, -hSpace * scale * (i + 1)), 0, 0, 0);
                            line2.AddVertexAt(1, pts[0].Convert2D(), 0, 0, 0);
                            ext = ext.Add(new Extents2d(line2.Bounds.Value.MinPoint.Convert2D(), line2.Bounds.Value.MaxPoint.Convert2D()));
                            res.Add(line2);

                            line3.AddVertexAt(0, pts[1].Convert2D(), 0, 0, 0);
                            line3.AddVertexAt(1, list[list.Count - 1].Convert2D(scale / 2, -hSpace * scale * (i + 1)), 0, 0, 0);
                            ext = ext.Add(new Extents2d(line3.Bounds.Value.MinPoint.Convert2D(), line3.Bounds.Value.MaxPoint.Convert2D()));
                            res.Add(line3);
                        }
                        else if ((list[0].Y - hSpace * scale * (i + 1)) <= arc1.Center.Y + arcRadius * scale * Math.Cos(GeTools.DegreeToRadian(arcAngle / 2)) &&
                            (list[0].Y - hSpace * scale * (i + 1)) >= arc3.Center.Y - arcRadius * scale)
                        {
                            //右边弧形交点计算
                            Line l1 = new Line(list[i].Convert3D(0, -hSpace * scale * (i + 1)), list[i].Convert3D(pileHeight * 2 * scale, -hSpace * scale * (i + 1)));
                            pts.Clear();
                            l1.IntersectWith((Entity)arc3, Intersect.ExtendBoth, pts, IntPtr.Zero, IntPtr.Zero);

                            if (pts == null || pts.Count == 0)
                            {
                                continue;
                            }
                            
                            line2.AddVertexAt(0, pts[0].Convert2D(), 0, 0, 0);
                            line2.AddVertexAt(0, pts[1].Convert2D(), 0, 0, 0);
                            ext = ext.Add(new Extents2d(line2.Bounds.Value.MinPoint.Convert2D(), line2.Bounds.Value.MaxPoint.Convert2D()));
                            res.Add(line2);

                            line3.AddVertexAt(0, pts[0].Convert2D(), 0, 0, 0);
                            line3.AddVertexAt(1, list[list.Count - 1].Convert2D(scale / 2, -hSpace * scale * (i + 1)), 0, 0, 0);
                            ext = ext.Add(new Extents2d(line3.Bounds.Value.MinPoint.Convert2D(), line3.Bounds.Value.MaxPoint.Convert2D()));
                            //res.Add(line3);
                        }
                    }
                }
                #endregion

                #region 绘制边框线
                // 计算两边线的坐标
                double cosHeight = arcRadius * Math.Cos(GeTools.DegreeToRadian(arcAngle / 2));
                Point2d leftPt = new Point2d(arc2.Center.X - arcRadius / 2, arc2.Center.Y - cosHeight);
                Point2d rightPt = new Point2d(arc3.Center.X + arcRadius / 2, arc3.Center.Y - cosHeight);
                Polyline line5 = new Polyline() { Closed = false, Layer = "粗线" };
                line5.AddVertexAt(0, leftPt, 0, 0, 0);
                line5.AddVertexAt(1, leftPt.Convert2D(0, pileHeight*0.7/*40 * scale*/), 0, 0, 0);
                ext = ext.Add(new Extents2d(line5.Bounds.Value.MinPoint.Convert2D(), line5.Bounds.Value.MaxPoint.Convert2D()));
                res.Add(line5);

                Polyline line6 = new Polyline() { Closed = false, Layer = "粗线" };
                Point2d pt6 = leftPt.Convert2D(0, pileHeight * 0.7/*40 * scale*/);
                Point2d pt7 = pt6.Convert2D(-5*scale);
                Point2d pt8 = pt7.Convert2D(0, pileHeight*0.1);
                Point2d pt9 = pt8.Convert2D(scale, scale);
                Point2d pt10 = pt9.Convert2D(-scale*2, scale);
                Point2d pt11 = pt10.Convert2D(scale, scale);
                Point2d pt12 = pt11.Convert2D(0, pileHeight*0.15);
                Point2d pt13 = pt12.Convert2D(arcRadius*2+ 10*scale);
                Point2d pt14 = pt13.Convert2D(0,-pileHeight*0.15);
                Point2d pt15 = pt14.Convert2D(-scale,-scale);
                Point2d pt16 = pt15.Convert2D(scale*2, -scale);
                Point2d pt17 = pt16.Convert2D(-scale, -scale);
                Point2d pt18 = pt17.Convert2D(0, -pileHeight * 0.1);
                Point2d pt19 = pt18.Convert2D(-5*scale);
                line6.AddVertexAt(0, pt6, 0, 0, 0);
                line6.AddVertexAt(1, pt7, 0, 0, 0);
                line6.AddVertexAt(2, pt8, 0, 0, 0);
                line6.AddVertexAt(3, pt9, 0, 0, 0);
                line6.AddVertexAt(4, pt10, 0, 0, 0);
                line6.AddVertexAt(5, pt11, 0, 0, 0);
                line6.AddVertexAt(6, pt12, 0, 0, 0);
                line6.AddVertexAt(7, pt13, 0, 0, 0);
                line6.AddVertexAt(8, pt14, 0, 0, 0);
                line6.AddVertexAt(9, pt15, 0, 0, 0);
                line6.AddVertexAt(10, pt16, 0, 0, 0);
                line6.AddVertexAt(11, pt17, 0, 0, 0);
                line6.AddVertexAt(12, pt18, 0, 0, 0);
                line6.AddVertexAt(13, pt19, 0, 0, 0);
                line6.AddVertexAt(14, rightPt, 0, 0, 0);
                ext = ext.Add(new Extents2d(line6.Bounds.Value.MinPoint.Convert2D(), line6.Bounds.Value.MaxPoint.Convert2D()));
                res.Add(line6);
                #endregion

                var TX1 = Matrix3d.Rotation(GeTools.DegreeToRadian(rotation), Vector3d.ZAxis, pt.Convert3D(radius, -30 * scale));

                #region 绘制其他标记
                if (!string.IsNullOrEmpty(T1))
                {
                    Point3d startPoint = pt19.Convert3D(-2.5*scale,-2.5*scale);

                    // 带箭头直线
                    //DBObjectCollection res1 = DimPloter.ArrowLine(db, ref ext, startPoint, 5,scale,270);
                    //foreach (DBObject item in res1)
                    //{
                    //    Entity pr = (Entity)item;
                    //    pr.TransformBy(TX1);
                    //}

                    // 直线
                    Polyline pl1 = new Polyline() { Closed = false, Layer = "标注" };
                    pl1.AddVertexAt(0,startPoint.Convert2D(),0,0,0);
                    pl1.AddVertexAt(0, startPoint.Convert2D(15*scale), 0, 0, 0);
                    ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.Convert2D(), pl1.Bounds.Value.MaxPoint.Convert2D()));
                    res.Add(pl1);

                    // 圆形标记
                    DBObjectCollection res2 = DimPloter.CircularMark(db, ref ext, startPoint.Convert3D(15 * scale), T1, Extensions.curFont, scale);
                    foreach (DBObject item in res2)
                    {
                        Entity pr = (Entity)item;
                        pr.TransformBy(TX1);
                    }
                }

                if (!string.IsNullOrEmpty(T2))
                {
                    Point3d startPoint = rightPt.Convert3D(5 * scale, 10 * scale);

                    // 直线
                    //DBObjectCollection res3 = DimPloter.ArrowLine(db, ref ext, startPoint, 5, scale, 180);
                    //foreach (DBObject item in res3)
                    //{
                    //    Entity pr = (Entity)item;
                    //    pr.TransformBy(TX1);
                    //}

                    // 圆形标记
                    DBObjectCollection res4 = DimPloter.CircularMark(db, ref ext, startPoint.Convert3D(), T2, Extensions.curFont, scale);
                    foreach (DBObject item in res4)
                    {
                        Entity pr = (Entity)item;
                        pr.TransformBy(TX1);
                    }

                    int num = (int)(2 * radius / scale)-1;
                    DBObjectCollection res5 = new DBObjectCollection();
                    for (int i = num; i >0;--i)
                    {
                        Point3d p = new Point3d(pt.X+2*radius-scale*(num-i),startPoint.Y,0);
                        //DBObjectCollection r = DimPloter.ArrowLine(db, ref ext, p, 1, scale, 180);

                        //foreach (DBObject item in r)
                        //{
                        //    res5.Add(item);
                        //}
                    }
                    foreach (DBObject item in res5)
                    {
                        Entity pr = (Entity)item;
                        pr.TransformBy(TX1);
                    }
                }

                if (!string.IsNullOrEmpty(T3))
                {
                    Point2d p = list[0].Convert2D((list[list.Count-1].X- list[0].X)/2, list[0].Y+scale);
                    TextPloter.PlotText(db, ref ext, TextPloter.eTxtLocation.E_TOP, p, T3,scale,Extensions.curFont);
                }
                #endregion
                //var TX1 = Matrix3d.Rotation(GeTools.DegreeToRadian(rotation), Vector3d.ZAxis, pt.Convert3D(radius,-30*scale));
                foreach (DBObject item in res)
                {
                    Entity pr = (Entity)item;
                    pr.TransformBy(TX1);
                }

                foreach (DBObject drawitem in res)
                {
                    recorder.AppendEntity((Entity)drawitem);
                    tr.AddNewlyCreatedDBObject(drawitem, true);
                }
                tr.Commit();
            }
        }

        /// <summary>
        /// 圆柱断面图
        /// </summary>
        /// <param name="db"></param>
        /// <param name="ext"></param>
        /// <param name="pt">圆柱左上切点</param>
        /// <param name="radius">圆柱半径</param>
        /// <param name="height">断面高度</param>
        /// <param name="isUp">true：上断面； false：下断面</param>
        public static void CreateCylindricalSection(Database db, ref Extents2d ext, Point3d pt,
            double radius, double height, bool isUp, double scale = 100)
        {
            DBObjectCollection res = new DBObjectCollection();
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                double arcAngle = 60;
                double cosH = radius * Math.Cos(GeTools.DegreeToRadian(arcAngle/2));
                if (isUp)
                {
                    // 绘制弧线
                    Arc arc1 = new Arc(pt.Convert3D(-radius/2* scale, -cosH * scale+ height), radius * scale, GeTools.DegreeToRadian(60), GeTools.DegreeToRadian(60 + arcAngle)) { Layer = "细线" };
                    ext = ext.Add(new Extents2d(arc1.Bounds.Value.MinPoint.Convert2D(), arc1.Bounds.Value.MaxPoint.Convert2D()));
                    res.Add(arc1);

                    Arc arc2 = new Arc(pt.Convert3D((radius / 2) * scale, -cosH * scale + height), radius * scale, GeTools.DegreeToRadian(60), GeTools.DegreeToRadian(60 + arcAngle)) { Layer = "细线" };
                    ext = ext.Add(new Extents2d(arc2.Bounds.Value.MinPoint.Convert2D(), arc2.Bounds.Value.MaxPoint.Convert2D()));
                    res.Add(arc2);

                    Arc arc3 = new Arc(pt.Convert3D(-radius / 2 * scale, cosH * scale + height), radius * scale, GeTools.DegreeToRadian(240), GeTools.DegreeToRadian(240 + arcAngle)) { Layer = "细线" };
                    ext = ext.Add(new Extents2d(arc3.Bounds.Value.MinPoint.Convert2D(), arc3.Bounds.Value.MaxPoint.Convert2D()));
                    res.Add(arc3);

                    // 直线
                    Polyline pl1 = new Polyline() { Closed = false, Layer = "粗线" };
                   
                    pl1.AddVertexAt(0, pt.Convert2D(-radius * scale, height), 0, 0, 0);
                    pl1.AddVertexAt(1, pt.Convert2D(-radius * scale), 0, 0, 0);
                    pl1.AddVertexAt(2, pt.Convert2D(radius * scale), 0, 0, 0);
                    pl1.AddVertexAt(3, pt.Convert2D(radius * scale, height), 0, 0, 0);
                    ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.Convert2D(), pl1.Bounds.Value.MaxPoint.Convert2D()));
                    res.Add(pl1);
                   

                    // 中心线
                    Polyline pl4 = new Polyline() { Closed = false, Layer = "中心线" };
                    pl4.AddVertexAt(0, pt.Convert2D(0, -5*scale), 0, 0, 0);
                    pl4.AddVertexAt(1, pt.Convert2D(0, height + 5*scale), 0, 0, 0);
                    ext = ext.Add(new Extents2d(pl4.Bounds.Value.MinPoint.Convert2D(), pl4.Bounds.Value.MaxPoint.Convert2D()));
                    res.Add(pl4);
                }
                else
                {
                    // 绘制弧线
                    Arc arc1 = new Arc(pt.Convert3D(-radius / 2 * scale, -(height -cosH * scale)), radius * scale, GeTools.DegreeToRadian(240), GeTools.DegreeToRadian(240 + arcAngle)) { Layer = "细线" };
                    ext = ext.Add(new Extents2d(arc1.Bounds.Value.MinPoint.Convert2D(), arc1.Bounds.Value.MaxPoint.Convert2D()));
                    res.Add(arc1);

                    Arc arc2 = new Arc(pt.Convert3D((radius / 2) * scale, -(height - cosH * scale)), radius * scale, GeTools.DegreeToRadian(240), GeTools.DegreeToRadian(240 + arcAngle)) { Layer = "细线" };
                    ext = ext.Add(new Extents2d(arc2.Bounds.Value.MinPoint.Convert2D(), arc2.Bounds.Value.MaxPoint.Convert2D()));
                    res.Add(arc2);

                    Arc arc3 = new Arc(pt.Convert3D((radius / 2) * scale, -(height+ cosH * scale)), radius * scale, GeTools.DegreeToRadian(60), GeTools.DegreeToRadian(60 + arcAngle)) { Layer = "细线" };
                    ext = ext.Add(new Extents2d(arc3.Bounds.Value.MinPoint.Convert2D(), arc3.Bounds.Value.MaxPoint.Convert2D()));
                    res.Add(arc3);

                    // 直线
                    Polyline pl1 = new Polyline() { Closed = false, Layer = "粗线" };
                    pl1.AddVertexAt(0, pt.Convert2D(-radius * scale, -height), 0, 0, 0);
                    pl1.AddVertexAt(1, pt.Convert2D(-radius * scale), 0, 0, 0);
                    pl1.AddVertexAt(2, pt.Convert2D(radius * scale), 0, 0, 0);
                    pl1.AddVertexAt(3, pt.Convert2D(radius * scale, -height), 0, 0, 0);
                    ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.Convert2D(), pl1.Bounds.Value.MaxPoint.Convert2D()));
                    res.Add(pl1);                   

                    // 中心线
                    Polyline pl4 = new Polyline() { Closed = false, Layer = "中心线" };
                    pl4.AddVertexAt(0, pt.Convert2D(0, 5 * scale), 0, 0, 0);
                    pl4.AddVertexAt(1, pt.Convert2D(0, -height - 5 * scale), 0, 0, 0);
                    ext = ext.Add(new Extents2d(pl4.Bounds.Value.MinPoint.Convert2D(), pl4.Bounds.Value.MaxPoint.Convert2D()));
                    res.Add(pl4);
                }
                
                foreach (DBObject drawitem in res)
                {
                    recorder.AppendEntity((Entity)drawitem);
                    tr.AddNewlyCreatedDBObject(drawitem, true);
                }
                tr.Commit();
            }
        }

        public static void CreateArc(Database db, ref Extents2d ext, Point3d pt,
        double radius,double stangle,double endangle)
        {
            DBObjectCollection res = new DBObjectCollection();
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                // 绘制圆
                Arc arc1 = new Arc(pt.Convert3D(), radius, GeTools.DegreeToRadian(stangle), GeTools.DegreeToRadian(endangle)) { Layer = "细线" };
                ext = ext.Add(new Extents2d(arc1.Bounds.Value.MinPoint.Convert2D(), arc1.Bounds.Value.MaxPoint.Convert2D()));
                res.Add(arc1);
                foreach (DBObject drawitem in res)
                {
                    recorder.AppendEntity((Entity)drawitem);
                    tr.AddNewlyCreatedDBObject(drawitem, true);
                }
                tr.Commit();
            }
           
        }
        public static void CreateCicleSection(Database db, ref Extents2d ext, Point3d pt,
        double radius,double scale = 100,string layer= "粗线")
        {
            DBObjectCollection res = new DBObjectCollection();
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                // 绘制圆
                Circle exCircle = new Circle(pt.Convert3D(), Vector3d.ZAxis, radius*scale) { Layer = layer, ColorIndex=2,LinetypeScale=scale};
                res.Add(exCircle);
                ext = ext.Add(new Extents2d(exCircle.Bounds.Value.MinPoint.Convert2D(), exCircle.Bounds.Value.MaxPoint.Convert2D()));

                foreach (DBObject drawitem in res)
                {
                    recorder.AppendEntity((Entity)drawitem);
                    tr.AddNewlyCreatedDBObject(drawitem, true);
                }
                tr.Commit();
            }
        }

        /// <summary>
        /// 钢筋工点图
        /// </summary>
        /// <param name="db"></param>
        /// <param name="ext"></param>
        /// <param name="direction"></param>
        /// <param name="list"></param>
        /// <param name="T1"></param>
        /// <param name="bound">左右/上下元素个数分界线</param>
        /// <param name="midbound">左右/上下元素个数分界线</param>
        /// <param name="scale"></param>
        public static void CreateRebarPointLine(Database db, ref Extents2d ext, eDirection direction,
            List<Point3d> list, string T1,int bound, int midbound, double scale=100,bool isleft=false)
        {
            DBObjectCollection res = new DBObjectCollection();
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                if(list == null || list.Count <= 1)
                {
                    return;
                }
                #region 绘制
                double height = 4 * scale;
                double angle = 70;
                double pointSpace = height/Math.Tan(GeTools.DegreeToRadian(angle));
                switch(direction)
                {
                    case eDirection.E_LEFT:
                        {
                            //if (Math.Abs(list[0].X - list[list.Count - 1].X) + 2.5 * scale <= pointSpace * (list.Count - 1))
                            //    break;
                            // 左边
                            for (int i = 0; i < bound && i< list.Count; ++i)
                            {
                                Polyline pl1 = new Polyline() { Closed = false, Layer = "粗线", ColorIndex = 4 };
                                pl1.AddVertexAt(0, list[i].Convert2D(), 0, 0, 0);
                                pl1.AddVertexAt(0, list[i].Convert2D(-height, -pointSpace), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.Convert2D(), pl1.Bounds.Value.MaxPoint.Convert2D()));
                                res.Add(pl1);
                            }

                            // 右边
                            for (int i = list.Count- bound; i < list.Count; ++i)
                            {
                                Polyline pl2 = new Polyline() { Closed = false, Layer = "粗线", ColorIndex = 4 };
                                pl2.AddVertexAt(0, list[i].Convert2D(), 0, 0, 0);
                                pl2.AddVertexAt(0, list[i].Convert2D(-height, pointSpace), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl2.Bounds.Value.MinPoint.Convert2D(), pl2.Bounds.Value.MaxPoint.Convert2D()));
                                res.Add(pl2);
                            }
                            // 左边中间
                            for (int i = list.Count/2-3-midbound ; i < list.Count / 2-3 && i > 0; ++i)
                            {
                                Polyline pl1 = new Polyline() { Closed = false, Layer = "粗线", ColorIndex = 4 };
                                pl1.AddVertexAt(0, list[i].Convert2D(), 0, 0, 0);
                                pl1.AddVertexAt(0, list[i].Convert2D(-height, -pointSpace), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.Convert2D(), pl1.Bounds.Value.MaxPoint.Convert2D()));
                                res.Add(pl1);
                            }

                            // 右边中间
                            for (int i = list.Count/2+3; i < list.Count / 2 + 3+midbound && i < list.Count; ++i)
                            {
                                Polyline pl2 = new Polyline() { Closed = false, Layer = "粗线", ColorIndex = 4 };
                                pl2.AddVertexAt(0, list[i].Convert2D(), 0, 0, 0);
                                pl2.AddVertexAt(0, list[i].Convert2D(-height, pointSpace), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl2.Bounds.Value.MinPoint.Convert2D(), pl2.Bounds.Value.MaxPoint.Convert2D()));
                                res.Add(pl2);
                            }
                            double width =Math.Abs(list[list.Count - 1].Convert2D(-height, pointSpace).Y - list[0].Convert2D(-height, -pointSpace).Y) - 2.5 * 2 * scale;
                            Polyline pl3 = new Polyline() { Closed = false, Layer = "粗线", ColorIndex = 4 };
                            pl3.AddVertexAt(0, list[0].Convert2D(-height, -pointSpace), 0, 0, 0);
                            pl3.AddVertexAt(1, list[0].Convert2D(-height, -pointSpace - width/2), 0, 0, 0);
                            ext = ext.Add(new Extents2d(pl3.Bounds.Value.MinPoint.Convert2D(), pl3.Bounds.Value.MaxPoint.Convert2D()));
                            res.Add(pl3);

                            Polyline pl4 = new Polyline() { Closed = false, Layer = "粗线", ColorIndex = 4 };
                            pl4.AddVertexAt(0, list[list.Count-1].Convert2D(-height, pointSpace+width/2), 0, 0, 0);
                            pl4.AddVertexAt(1, list[list.Count - 1].Convert2D(-height, pointSpace), 0, 0, 0);
                            ext = ext.Add(new Extents2d(pl4.Bounds.Value.MinPoint.Convert2D(), pl4.Bounds.Value.MaxPoint.Convert2D()));
                            res.Add(pl4);

                            // 圆形标记
                            DimPloter.CircularMark(db, ref ext, list[0].Convert3D(-height-2.5*scale, -pointSpace - width/2-2.5*scale),
                                T1, Extensions.curFont, scale);
                            break;
                        }
                    case eDirection.E_RIGHT:
                        {
                            //if (Math.Abs(list[0].X - list[list.Count - 1].X) + 2.5 * scale <= pointSpace * (list.Count - 1))
                            //    break;
                            // 左边
                            for (int i = 0; i < bound && i < list.Count; ++i)
                            {
                                Polyline pl1 = new Polyline() { Closed = false, Layer = "粗线", ColorIndex = 4 };
                                pl1.AddVertexAt(0, list[i].Convert2D(), 0, 0, 0);
                                pl1.AddVertexAt(0, list[i].Convert2D(height, -pointSpace), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.Convert2D(), pl1.Bounds.Value.MaxPoint.Convert2D()));
                                res.Add(pl1);
                            }

                            // 右边
                            for (int i = list.Count - bound; i < list.Count; ++i)
                            {
                                Polyline pl2 = new Polyline() { Closed = false, Layer = "粗线", ColorIndex = 4 };
                                pl2.AddVertexAt(0, list[i].Convert2D(), 0, 0, 0);
                                pl2.AddVertexAt(0, list[i].Convert2D(height, pointSpace), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl2.Bounds.Value.MinPoint.Convert2D(), pl2.Bounds.Value.MaxPoint.Convert2D()));
                                res.Add(pl2);
                            }
                            // 左边中间
                            for (int i = list.Count / 2 - 3 - midbound; i < list.Count / 2 - 3 && i > 0; ++i)
                            {
                                Polyline pl1 = new Polyline() { Closed = false, Layer = "粗线", ColorIndex = 4 };
                                pl1.AddVertexAt(0, list[i].Convert2D(), 0, 0, 0);
                                pl1.AddVertexAt(0, list[i].Convert2D(height, -pointSpace), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.Convert2D(), pl1.Bounds.Value.MaxPoint.Convert2D()));
                                res.Add(pl1);
                            }

                            // 右边中间
                            for (int i = list.Count / 2 + 3; i < list.Count / 2 + 3 + midbound && i < list.Count; ++i)
                            {
                                Polyline pl2 = new Polyline() { Closed = false, Layer = "粗线", ColorIndex = 4 };
                                pl2.AddVertexAt(0, list[i].Convert2D(), 0, 0, 0);
                                pl2.AddVertexAt(0, list[i].Convert2D(height, pointSpace), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl2.Bounds.Value.MinPoint.Convert2D(), pl2.Bounds.Value.MaxPoint.Convert2D()));
                                res.Add(pl2);
                            }
                            double width = Math.Abs(list[list.Count - 1].Convert2D(height, pointSpace).Y - list[0].Convert2D(height, -pointSpace).Y) - 2.5 * 2 * scale;
                            Polyline pl3 = new Polyline() { Closed = false, Layer = "粗线", ColorIndex = 4 };
                            pl3.AddVertexAt(0, list[0].Convert2D(height, -pointSpace), 0, 0, 0);
                            pl3.AddVertexAt(1, list[0].Convert2D(height, -pointSpace - width / 2), 0, 0, 0);
                            ext = ext.Add(new Extents2d(pl3.Bounds.Value.MinPoint.Convert2D(), pl3.Bounds.Value.MaxPoint.Convert2D()));
                            res.Add(pl3);

                            Polyline pl4 = new Polyline() { Closed = false, Layer = "粗线", ColorIndex = 4 };
                            pl4.AddVertexAt(0, list[list.Count - 1].Convert2D(height, pointSpace + width / 2), 0, 0, 0);
                            pl4.AddVertexAt(1, list[list.Count - 1].Convert2D(height, pointSpace), 0, 0, 0);
                            ext = ext.Add(new Extents2d(pl4.Bounds.Value.MinPoint.Convert2D(), pl4.Bounds.Value.MaxPoint.Convert2D()));
                            res.Add(pl4);

                            // 圆形标记
                            DimPloter.CircularMark(db, ref ext, list[0].Convert3D(height - 2.5 * scale, -pointSpace - width / 2 - 2.5 * scale),
                                T1, Extensions.curFont, scale);
                            break;
                        }
                    case eDirection.E_TOP:
                        {
                            //if (Math.Abs(list[0].X - list[list.Count - 1].X) - 2.5 * scale <= pointSpace * (list.Count - 1))
                            //    break;

                            // 左边
                            for (int i = 0; i < bound && i < list.Count; ++i)
                            {
                                Polyline pl1 = new Polyline() { Closed = false, Layer = "粗线", ColorIndex = 4 };
                                pl1.AddVertexAt(0, list[i].Convert2D(), 0, 0, 0);
                                pl1.AddVertexAt(0, list[i].Convert2D(pointSpace, -height), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.Convert2D(), pl1.Bounds.Value.MaxPoint.Convert2D()));
                                res.Add(pl1);
                            }

                            // 右边
                            for (int i = list.Count - bound; i < list.Count; ++i)
                            {
                                Polyline pl2 = new Polyline() { Closed = false, Layer = "粗线", ColorIndex = 4 };
                                pl2.AddVertexAt(0, list[i].Convert2D(), 0, 0, 0);
                                pl2.AddVertexAt(0, list[i].Convert2D(-pointSpace, -height), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl2.Bounds.Value.MinPoint.Convert2D(), pl2.Bounds.Value.MaxPoint.Convert2D()));
                                res.Add(pl2);
                            }
                            // 左边中间
                            for (int i = list.Count / 2 - 3 - midbound; i < list.Count / 2 - 3 && i > 0; ++i)
                            {
                                Polyline pl1 = new Polyline() { Closed = false, Layer = "粗线", ColorIndex = 4 };
                                pl1.AddVertexAt(0, list[i].Convert2D(), 0, 0, 0);
                                pl1.AddVertexAt(0, list[i].Convert2D(pointSpace, -height), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.Convert2D(), pl1.Bounds.Value.MaxPoint.Convert2D()));
                                res.Add(pl1);
                            }

                            // 右边中间
                            for (int i = list.Count / 2 + 3; i < list.Count / 2 + 3 + midbound && i < list.Count; ++i)
                            {
                                Polyline pl2 = new Polyline() { Closed = false, Layer = "粗线", ColorIndex = 4 };
                                pl2.AddVertexAt(0, list[i].Convert2D(), 0, 0, 0);
                                pl2.AddVertexAt(0, list[i].Convert2D(-pointSpace, -height), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl2.Bounds.Value.MinPoint.Convert2D(), pl2.Bounds.Value.MaxPoint.Convert2D()));
                                res.Add(pl2);
                            }
                            double width = list[list.Count - 1].Convert2D(-pointSpace, -height).X - list[0].Convert2D(pointSpace, -height).X - 2.5 * 2 * scale;
                            if (isleft)
                            {
                                width = list[list.Count - 1].Convert2D(-pointSpace, -height).X - list[0].Convert2D(pointSpace, -height).X;
                            }
                            Polyline pl3 = new Polyline() { Closed = false, Layer = "粗线", ColorIndex = 4 };
                            pl3.AddVertexAt(0, list[0].Convert2D(pointSpace, -height), 0, 0, 0);
                            pl3.AddVertexAt(1, list[0].Convert2D(pointSpace + width / 2, -height), 0, 0, 0);
                            ext = ext.Add(new Extents2d(pl3.Bounds.Value.MinPoint.Convert2D(), pl3.Bounds.Value.MaxPoint.Convert2D()));
                            res.Add(pl3);

                            Polyline pl4 = new Polyline() { Closed = false, Layer = "粗线", ColorIndex = 4 };
                            pl4.AddVertexAt(0, list[list.Count - 1].Convert2D(-pointSpace- width / 2, -height), 0, 0, 0);
                            pl4.AddVertexAt(1, list[list.Count - 1].Convert2D(-pointSpace, -height), 0, 0, 0);
                            ext = ext.Add(new Extents2d(pl4.Bounds.Value.MinPoint.Convert2D(), pl4.Bounds.Value.MaxPoint.Convert2D()));
                            res.Add(pl4);

                            if(isleft)
                            {
                                pl4 = new Polyline() { Closed = false, Layer = "粗线", ColorIndex = 4 };
                                pl4.AddVertexAt(0, list[list.Count - 1].Convert2D(-pointSpace+5*scale, -height), 0, 0, 0);
                                pl4.AddVertexAt(1, list[list.Count - 1].Convert2D(-pointSpace, -height), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl4.Bounds.Value.MinPoint.Convert2D(), pl4.Bounds.Value.MaxPoint.Convert2D()));
                                res.Add(pl4);
                                DimPloter.CircularMark(db, ref ext, list[list.Count - 1].Convert3D(-pointSpace + 5 * scale, -height),
                                T1, Extensions.curFont, scale);
                            }
                            else
                            // 圆形标记
                            DimPloter.CircularMark(db, ref ext, list[0].Convert3D(pointSpace+width/2, -height),
                                T1, Extensions.curFont, scale);
                            break;
                        }
                    case eDirection.E_BOTTOM:
                        {
                            //if (Math.Abs(list[0].X - list[list.Count - 1].X) - 2.5 * scale <= pointSpace * (list.Count - 1))
                            //    break;
                            // 左边
                            for (int i = 0; i < bound && i < list.Count; ++i)
                            {
                                Polyline pl1 = new Polyline() { Closed = false, Layer = "粗线", ColorIndex = 4 };
                                pl1.AddVertexAt(0, list[i].Convert2D(), 0, 0, 0);
                                pl1.AddVertexAt(0, list[i].Convert2D(pointSpace, height), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.Convert2D(), pl1.Bounds.Value.MaxPoint.Convert2D()));
                                res.Add(pl1);
                            }

                            // 右边
                            for (int i = list.Count - bound; i < list.Count; ++i)
                            {
                                Polyline pl2 = new Polyline() { Closed = false, Layer = "粗线", ColorIndex = 4 };
                                pl2.AddVertexAt(0, list[i].Convert2D(), 0, 0, 0);
                                pl2.AddVertexAt(0, list[i].Convert2D(-pointSpace, height), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl2.Bounds.Value.MinPoint.Convert2D(), pl2.Bounds.Value.MaxPoint.Convert2D()));
                                res.Add(pl2);
                            }
                            // 左边中间
                            for (int i = list.Count / 2 - 3 - midbound; i < list.Count / 2 - 3 && i > 0; ++i)
                            {
                                Polyline pl1 = new Polyline() { Closed = false, Layer = "粗线", ColorIndex = 4 };
                                pl1.AddVertexAt(0, list[i].Convert2D(), 0, 0, 0);
                                pl1.AddVertexAt(0, list[i].Convert2D(pointSpace, height), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.Convert2D(), pl1.Bounds.Value.MaxPoint.Convert2D()));
                                res.Add(pl1);
                            }

                            // 右边中间
                            for (int i = list.Count / 2 + 3; i < list.Count / 2 + 3 + midbound && i < list.Count; ++i)
                            {
                                Polyline pl2 = new Polyline() { Closed = false, Layer = "粗线", ColorIndex = 4 };
                                pl2.AddVertexAt(0, list[i].Convert2D(), 0, 0, 0);
                                pl2.AddVertexAt(0, list[i].Convert2D(-pointSpace, height), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl2.Bounds.Value.MinPoint.Convert2D(), pl2.Bounds.Value.MaxPoint.Convert2D()));
                                res.Add(pl2);
                            }
                            double width = list[list.Count - 1].Convert2D(-pointSpace, height).X - list[0].Convert2D(pointSpace, height).X - 2.5*2*scale;
                            Polyline pl3 = new Polyline() { Closed = false, Layer = "粗线", ColorIndex = 4 };
                            pl3.AddVertexAt(0, list[0].Convert2D(pointSpace, height), 0, 0, 0);
                            pl3.AddVertexAt(1, list[0].Convert2D(pointSpace + width / 2, height), 0, 0, 0);
                            ext = ext.Add(new Extents2d(pl3.Bounds.Value.MinPoint.Convert2D(), pl3.Bounds.Value.MaxPoint.Convert2D()));
                            res.Add(pl3);

                            Polyline pl4 = new Polyline() { Closed = false, Layer = "粗线", ColorIndex = 4 };
                            pl4.AddVertexAt(0, list[list.Count - 1].Convert2D(-pointSpace - width / 2, height), 0, 0, 0);
                            pl4.AddVertexAt(1, list[list.Count - 1].Convert2D(-pointSpace, height), 0, 0, 0);
                            ext = ext.Add(new Extents2d(pl4.Bounds.Value.MinPoint.Convert2D(), pl4.Bounds.Value.MaxPoint.Convert2D()));
                            res.Add(pl4);

                            // 圆形标记
                            DimPloter.CircularMark(db, ref ext, list[0].Convert3D(pointSpace + width/2, height),
                                T1, Extensions.curFont, scale);
                            break;
                        }
                    default:
                        break;
                }
                #endregion
                foreach (DBObject drawitem in res)
                {
                    recorder.AppendEntity((Entity)drawitem);
                    tr.AddNewlyCreatedDBObject(drawitem, true);
                }
                tr.Commit();
            }
        }


        public static void CreateBottomRebarPointLine(Database db, ref Extents2d ext, 
         List<Point3d> list, int bottomNum, double bottomSpace, string T1, int bound, int midbound, double scale = 100)
        {
            DBObjectCollection res = new DBObjectCollection();
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                if (list == null || list.Count <= 1)
                {
                    return;
                }
                #region 绘制
                double height = 3.2 * scale;
                double angle = 70;
                double pointSpace = height / Math.Tan(GeTools.DegreeToRadian(angle));

               
                for (int i = 0; i < bound && i < list.Count; ++i)
                {
                    Polyline pl1 = new Polyline() { Closed = false, Layer = "粗线", ColorIndex = 4 };
                    pl1.AddVertexAt(0, list[i].Convert2D(), 0, 0, 0);
                    pl1.AddVertexAt(0, list[i].Convert2D(pointSpace, height), 0, 0, 0);
                    ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.Convert2D(), pl1.Bounds.Value.MaxPoint.Convert2D()));
                    res.Add(pl1);
                    if (bottomNum > 0)
                    {
                        for (int m = 1; m < bottomNum; m++)
                        {
                            pl1 = new Polyline() { Closed = false, Layer = "粗线", ColorIndex = 4 };
                            pl1.AddVertexAt(0, list[i].Convert2D(0, -m * bottomSpace), 0, 0, 0);
                            pl1.AddVertexAt(0, list[i].Convert2D(pointSpace, height  ), 0, 0, 0);
                            ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.Convert2D(), pl1.Bounds.Value.MaxPoint.Convert2D()));
                            res.Add(pl1);
                        }
                    }
                }

                // 右边
                for (int i = list.Count - bound; i < list.Count; ++i)
                {
                    Polyline pl2 = new Polyline() { Closed = false, Layer = "粗线", ColorIndex = 4 };
                    pl2.AddVertexAt(0, list[i].Convert2D(), 0, 0, 0);
                    pl2.AddVertexAt(0, list[i].Convert2D(-pointSpace, height), 0, 0, 0);
                    ext = ext.Add(new Extents2d(pl2.Bounds.Value.MinPoint.Convert2D(), pl2.Bounds.Value.MaxPoint.Convert2D()));
                    res.Add(pl2);
                    if (bottomNum > 0)
                    {
                        for (int m = 1; m < bottomNum; m++)
                        {
                            pl2 = new Polyline() { Closed = false, Layer = "粗线", ColorIndex = 4 };
                            pl2.AddVertexAt(0, list[i].Convert2D(0, -m * bottomSpace), 0, 0, 0);
                            pl2.AddVertexAt(0, list[i].Convert2D(-pointSpace, height ), 0, 0, 0);
                            ext = ext.Add(new Extents2d(pl2.Bounds.Value.MinPoint.Convert2D(), pl2.Bounds.Value.MaxPoint.Convert2D()));
                            res.Add(pl2);
                        }
                    }
                }
                // 左边中间
                for (int i = list.Count / 2 - 3 - midbound; i < list.Count / 2 - 3 && i > 0; ++i)
                {
                    Polyline pl1 = new Polyline() { Closed = false, Layer = "粗线", ColorIndex = 4 };
                    pl1.AddVertexAt(0, list[i].Convert2D(), 0, 0, 0);
                    pl1.AddVertexAt(0, list[i].Convert2D(pointSpace, height), 0, 0, 0);
                    ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.Convert2D(), pl1.Bounds.Value.MaxPoint.Convert2D()));
                    res.Add(pl1);
                    if (bottomNum > 0)
                    {
                        for (int m = 1; m < bottomNum; m++)
                        {
                            pl1 = new Polyline() { Closed = false, Layer = "粗线", ColorIndex = 4 };
                            pl1.AddVertexAt(0, list[i].Convert2D(0, -m * bottomSpace), 0, 0, 0);
                            pl1.AddVertexAt(0, list[i].Convert2D(pointSpace, height), 0, 0, 0);
                            ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.Convert2D(), pl1.Bounds.Value.MaxPoint.Convert2D()));
                            res.Add(pl1);
                        }
                    }
                }

                // 右边中间
                for (int i = list.Count / 2 + 3; i < list.Count / 2 + 3 + midbound && i < list.Count; ++i)
                {
                    Polyline pl2 = new Polyline() { Closed = false, Layer = "粗线", ColorIndex = 4 };
                    pl2.AddVertexAt(0, list[i].Convert2D(), 0, 0, 0);
                    pl2.AddVertexAt(0, list[i].Convert2D(-pointSpace, height), 0, 0, 0);
                    ext = ext.Add(new Extents2d(pl2.Bounds.Value.MinPoint.Convert2D(), pl2.Bounds.Value.MaxPoint.Convert2D()));
                    res.Add(pl2);
                    if (bottomNum > 0)
                    {
                        for (int m = 1; m < bottomNum; m++)
                        {
                            pl2 = new Polyline() { Closed = false, Layer = "粗线", ColorIndex = 4 };
                            pl2.AddVertexAt(0, list[i].Convert2D(0, -m * bottomSpace), 0, 0, 0);
                            pl2.AddVertexAt(0, list[i].Convert2D(-pointSpace, height), 0, 0, 0);
                            ext = ext.Add(new Extents2d(pl2.Bounds.Value.MinPoint.Convert2D(), pl2.Bounds.Value.MaxPoint.Convert2D()));
                            res.Add(pl2);
                        }
                    }
                }
                double width = list[list.Count - 1].Convert2D(-pointSpace, height).X - list[0].Convert2D(pointSpace, height).X - 2.5 * 2 * scale;
                Polyline pl3 = new Polyline() { Closed = false, Layer = "粗线", ColorIndex = 4 };
                pl3.AddVertexAt(0, list[0].Convert2D(pointSpace, height), 0, 0, 0);
                pl3.AddVertexAt(1, list[0].Convert2D(pointSpace + width / 2, height), 0, 0, 0);
                ext = ext.Add(new Extents2d(pl3.Bounds.Value.MinPoint.Convert2D(), pl3.Bounds.Value.MaxPoint.Convert2D()));
                res.Add(pl3);

                Polyline pl4 = new Polyline() { Closed = false, Layer = "粗线", ColorIndex = 4 };
                pl4.AddVertexAt(0, list[list.Count - 1].Convert2D(-pointSpace - width / 2, height), 0, 0, 0);
                pl4.AddVertexAt(1, list[list.Count - 1].Convert2D(-pointSpace, height), 0, 0, 0);
                ext = ext.Add(new Extents2d(pl4.Bounds.Value.MinPoint.Convert2D(), pl4.Bounds.Value.MaxPoint.Convert2D()));
                res.Add(pl4);

                // 圆形标记
                DimPloter.CircularMark(db, ref ext, list[0].Convert3D(pointSpace + width / 2, height),
                    T1, Extensions.curFont, scale);


                #endregion
                foreach (DBObject drawitem in res)
                {
                    recorder.AppendEntity((Entity)drawitem);
                    tr.AddNewlyCreatedDBObject(drawitem, true);
                }
                tr.Commit();
            }
        }

        /// <summary>
        /// 圆形焊接图
        /// </summary>
        /// <param name="db"></param>
        /// <param name="ext"></param>
        /// <param name="pt"></param>
        /// <param name="radius"></param>
        /// <param name="T1"></param>
        /// <param name="T2"></param>
        /// <param name="T3"></param>
        /// <param name="T4"></param>
        /// <param name="linkArc">是否连接弧线</param>
        /// <param name="scale"></param>
        public static void CreateSingleSideWelding(Database db, ref Extents2d ext,Point2d pt,double radius,
            string T1, string T2, string T3, int T4, bool linkArc, double scale=100)
        {
            DBObjectCollection res = new DBObjectCollection();
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                // 箭头大小
                double length = 5;
                double height = 2;
                // 圆
                Circle exCircle = new Circle(pt.Convert3D(), Vector3d.ZAxis, radius) { Layer = "粗线" };
                res.Add(exCircle);
                ext = ext.Add(new Extents2d(exCircle.Bounds.Value.MinPoint.Convert2D(), exCircle.Bounds.Value.MaxPoint.Convert2D()));

                // 直径标记
                //Point3d pt = StartpPint.Convert3D(lineLength * scale);

                Polyline Line = new Polyline() { Closed = false, Layer = "标注" };
                Line.AddVertexAt(0, pt.Convert2D(-radius + length), 0, 0, 0);
                Line.AddVertexAt(1, pt.Convert2D(radius - length), 0, 0, 0);
                ext = ext.Add(new Extents2d(Line.Bounds.Value.MinPoint.Convert2D(), Line.Bounds.Value.MaxPoint.Convert2D()));
                res.Add(Line);

                // 绘制箭头
                double multi = scale / 10 > 1 ? scale / 10 : 1;
                Point3d pt1 = pt.Convert3D(-radius + length-5 * multi);
                Point3d pt2 = pt.Convert3D(-radius + length, 2 * multi);
                Point3d pt3 = pt.Convert3D(-radius + length, -2 * multi);
                Solid s1 = new Solid(pt1, pt2, pt3) { Layer = "标注" };
                ext = ext.Add(new Extents2d(s1.Bounds.Value.MinPoint.Convert2D(), s1.Bounds.Value.MaxPoint.Convert2D()));
                res.Add(s1);

                Point3d pt4 = pt.Convert3D(radius - length+5 * multi);
                Point3d pt5 = pt.Convert3D(radius - length, 2 * multi);
                Point3d pt6 = pt.Convert3D(radius - length, -2 * multi);
                Solid s2 = new Solid(pt4, pt5, pt6) { Layer = "标注" };
                ext = ext.Add(new Extents2d(s2.Bounds.Value.MinPoint.Convert2D(), s2.Bounds.Value.MaxPoint.Convert2D()));
                res.Add(s2);

                var TX1 = Matrix3d.Rotation(GeTools.DegreeToRadian(20), Vector3d.ZAxis, pt.Convert3D());
                foreach (DBObject item in res)
                {
                    Entity pr = (Entity)item;
                    pr.TransformBy(TX1);
                }

                // 文字
                TextPloter.PlotText(db, ref ext, TextPloter.eTxtLocation.E_TOP, pt.Convert2D(0,scale), T1, scale,Extensions.curFont, GeTools.DegreeToRadian(20));

                // 引线
                DimPloter.RebarWire(db, ref ext, pt.Convert2D(radius),T2, T3,T4,0,Extensions.curFont,10);

                // 弧线
                Arc arc1 = new Arc(pt.Convert3D(), radius+2*scale, GeTools.DegreeToRadian(240), GeTools.DegreeToRadian(300)) { Layer = "细线" };
                ext = ext.Add(new Extents2d(arc1.Bounds.Value.MinPoint.Convert2D(), arc1.Bounds.Value.MaxPoint.Convert2D()));
                res.Add(arc1);

                // 圆和弧线的连线
                if(linkArc)
                {
                    Polyline pl1 = new Polyline() { Closed = false, Layer = "标注" };
                    pl1.AddVertexAt(0, pt.Convert2D(0, -radius), 0, 0, 0);
                    pl1.AddVertexAt(1, pt.Convert2D(0, -radius - 2 * scale), 0, 0, 0);
                    ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.Convert2D(), pl1.Bounds.Value.MaxPoint.Convert2D()));
                    res.Add(pl1);

                    Polyline pl2 = new Polyline() { Closed = false, Layer = "标注" };
                    pl2.AddVertexAt(0, pt.Convert2D(-radius * Math.Sin(GeTools.DegreeToRadian(20)),
                        -radius * Math.Cos(GeTools.DegreeToRadian(20))), 0, 0, 0);
                    pl2.AddVertexAt(1, pt.Convert2D(-(radius + 2 * scale) * Math.Sin(GeTools.DegreeToRadian(20)),
                        -(radius + 2 * scale) * Math.Cos(GeTools.DegreeToRadian(20))), 0, 0, 0);
                    ext = ext.Add(new Extents2d(pl2.Bounds.Value.MinPoint.Convert2D(), pl2.Bounds.Value.MaxPoint.Convert2D()));
                    res.Add(pl2);

                    Polyline pl3 = new Polyline() { Closed = false, Layer = "标注" };
                    pl3.AddVertexAt(0, pt.Convert2D(-radius * Math.Sin(GeTools.DegreeToRadian(10)),
                        -radius * Math.Cos(GeTools.DegreeToRadian(10))), 0, 0, 0);
                    pl3.AddVertexAt(1, pt.Convert2D(-(radius + 2 * scale) * Math.Sin(GeTools.DegreeToRadian(10)),
                        -(radius + 2 * scale) * Math.Cos(GeTools.DegreeToRadian(10))), 0, 0, 0);
                    ext = ext.Add(new Extents2d(pl3.Bounds.Value.MinPoint.Convert2D(), pl3.Bounds.Value.MaxPoint.Convert2D()));
                    res.Add(pl3);

                    Polyline pl4 = new Polyline() { Closed = false, Layer = "标注" };
                    pl4.AddVertexAt(0, pt.Convert2D(radius * Math.Sin(GeTools.DegreeToRadian(20)),
                        -radius * Math.Cos(GeTools.DegreeToRadian(20))), 0, 0, 0);
                    pl4.AddVertexAt(1, pt.Convert2D((radius + 2 * scale) * Math.Sin(GeTools.DegreeToRadian(20)),
                        -(radius + 2 * scale) * Math.Cos(GeTools.DegreeToRadian(20))), 0, 0, 0);
                    ext = ext.Add(new Extents2d(pl4.Bounds.Value.MinPoint.Convert2D(), pl4.Bounds.Value.MaxPoint.Convert2D()));
                    res.Add(pl4);

                    Polyline pl5 = new Polyline() { Closed = false, Layer = "标注" };
                    pl5.AddVertexAt(0, pt.Convert2D(radius * Math.Sin(GeTools.DegreeToRadian(10)),
                        -radius * Math.Cos(GeTools.DegreeToRadian(10))), 0, 0, 0);
                    pl5.AddVertexAt(1, pt.Convert2D((radius + 2 * scale) * Math.Sin(GeTools.DegreeToRadian(10)),
                        -(radius + 2 * scale) * Math.Cos(GeTools.DegreeToRadian(10))), 0, 0, 0);
                    ext = ext.Add(new Extents2d(pl5.Bounds.Value.MinPoint.Convert2D(), pl5.Bounds.Value.MaxPoint.Convert2D()));
                    res.Add(pl5);
                }

                // 标注
                RotatedDimension Dim2 = DimPloter.AddRotDim(db,ref ext,pt.Convert3D(-(radius+ scale )/ 2), pt.Convert3D((radius+ scale) / 2), pt.Convert3D(0,-radius-scale*5),scale, 0);
                res.Add(Dim2);

                // 文字
                TextPloter.PlotText(db, ref ext, TextPloter.eTxtLocation.E_BOTTOM, pt.Convert2D(0, -radius - 7 * scale), "SINGLE SIDE WELDING",scale);

                foreach (DBObject drawitem in res)
                {
                    recorder.AppendEntity((Entity)drawitem);
                    tr.AddNewlyCreatedDBObject(drawitem, true);
                }

                tr.Commit();
                ext = ext.Add(new Extents2d(Dim2.Bounds.Value.MinPoint.Convert2D(), Dim2.Bounds.Value.MaxPoint.Convert2D()));
            }
        }

        /// <summary>
        /// 螺旋钢筋
        /// </summary>
        /// <param name="db"></param>
        /// <param name="ext"></param>
        /// <param name="pt"></param>
        /// <param name="radius">半径</param>
        /// <param name="height">高度</param>
        /// <param name="scale"></param>
        public static void CreateSpiralSteelBar(Database db, ref Extents2d ext,Point2d pt,double radius,
            double height, double scale=100)
        {
            DBObjectCollection res = new DBObjectCollection();
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                #region 螺旋钢筋
                // 螺旋钢筋的拉伸间隔
                double interval1 = 3;
                double interval2 = interval1*2;
                Point2d ptEnd1 = Point2d.Origin;
                Point2d ptEnd2 = Point2d.Origin;
                Point2d ptEnd = Point2d.Origin;
                List<Point2d> list = new List<Point2d>();
                Polyline Line = new Polyline() { Closed = false, Layer = "粗线" };
                Line.AddVertexAt(0, pt.Convert2D(), 0, 0, 0);
                Line.AddVertexAt(0, pt.Convert2D(radius * 2 * scale), 0, 0, 0);

                list.Add(pt.Convert2D());
                list.Add(pt.Convert2D(radius * 2 * scale));

                int num1 = (int)(height / 2 / interval1)+1;
                for (int i= 0; i < num1; ++i)
                {
                    Point2d pt1 = list[list.Count-1].Convert2D(-radius * 2 * scale, -interval1/2*scale);
                    list.Add(pt1.Convert2D());

                    Point2d pt2 = list[list.Count - 1].Convert2D(radius*2*scale, -interval1 / 2 * scale);
                    list.Add(pt2.Convert2D());

                    Line.AddVertexAt(0, pt1, 0, 0, 0);
                    Line.AddVertexAt(0, pt2, 0, 0, 0);
                    ptEnd1 = pt.Convert2D(radius * 2 * scale, -interval1 * scale * (i + 1));
                }

                int num2 = (int)(height / 2 / interval2);
                int j = 1;
                double offsetRadius = radius;
                for (int i = 0; i < num2; ++i)
                {
                    if ((i == num2 - 1) || (i == num2 - 2) || (i == num2 - 3))
                    {
                        double offset = radius * 2 * scale / 40;
                        Line.AddVertexAt(0, ptEnd2.Convert2D(-radius * 2 * scale + offset * j, -interval2 * j * scale), 0, 0, 0);
                        Line.AddVertexAt(0, ptEnd2.Convert2D(-j * offset, -interval2 * scale * j), 0, 0, 0);

                        list.Add(ptEnd2.Convert2D(-radius * 2 * scale + offset * j, -interval2 * (j - 1) * scale));
                        list.Add(ptEnd2.Convert2D(-j * offset, -interval2 * scale * j));
                        ptEnd = ptEnd2.Convert2D(-j * offset, -interval2 * scale * j);
                        offsetRadius = radius * 2 * scale - 6 * offset;
                        ++j;
                    }
                    else
                    {
                        double offset = interval2 * i + interval2 / 2;
                        if (i == 0)
                        {
                            offset = interval2 / 2;
                        }
                        Point2d pt1 = ptEnd1.Convert2D(-radius * 2 * scale, -offset * scale);
                        list.Add(pt1);
                        Line.AddVertexAt(0, pt1, 0, 0, 0);
                        Point2d pt2 = list[list.Count - 1].Convert2D(radius * 2 * scale, -interval2);
                        list.Add(pt2);
                        Line.AddVertexAt(0, pt2, 0, 0, 0);
                        ptEnd2 = pt2;
                    }
                }

                Line.AddVertexAt(0, ptEnd.Convert2D(-offsetRadius), 0, 0, 0);
                list.Add(ptEnd.Convert2D(-offsetRadius));
                ext = ext.Add(new Extents2d(Line.Bounds.Value.MinPoint.Convert2D(), Line.Bounds.Value.MaxPoint.Convert2D()));
                res.Add(Line);
                #endregion

                #region 引线
                // 直线
                Point2d startPt = pt.Convert2D(radius * 2 * scale * 3 / 4, interval1 / 2 * scale);
                Polyline pl1 = new Polyline() { Closed = false, Layer = "标注" };
                pl1.AddVertexAt(0, startPt, 0,0,0);
                pl1.AddVertexAt(0, startPt.Convert2D(10*scale,10 * scale), 0, 0, 0);
                ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.Convert2D(), pl1.Bounds.Value.MaxPoint.Convert2D()));
                res.Add(pl1);

                Polyline pl2 = new Polyline() { Closed = false, Layer = "标注" };
                pl2.AddVertexAt(0, startPt.Convert2D(10 * scale, 10 * scale), 0, 0, 0);
                pl2.AddVertexAt(0, startPt.Convert2D(10 * scale+ 30 * scale, 10 * scale), 0, 0, 0);
                ext = ext.Add(new Extents2d(pl2.Bounds.Value.MinPoint.Convert2D(), pl2.Bounds.Value.MaxPoint.Convert2D()));
                res.Add(pl2);

                // 文字
                TextPloter.PlotText(db,ref ext, TextPloter.eTxtLocation.E_TOP, startPt.Convert2D(10 * scale+ pl2.Length/2, 11 * scale),
                    "1T12",scale,Extensions.curFont);

                TextPloter.PlotText(db, ref ext, TextPloter.eTxtLocation.E_BOTTOM, startPt.Convert2D(10 * scale + pl2.Length / 2, 9 * scale),
                    "22.7357L+191409", scale, Extensions.curFont);

                // 圆形标记
                DimPloter.CircularMark(db, ref ext, startPt.Convert3D(10 * scale + 30 * scale, 10 * scale),
                    "4a", Extensions.curFont,10);
                #endregion

                #region 标注
                // 标注
                RotatedDimension Dim1 = DimPloter.AddRotDim(db,ref ext,pt.Convert3D(radius*scale), ptEnd1.Convert3D(), ptEnd1.Convert3D(5*scale), scale, 90);
                res.Add(Dim1);

                // 标注
                RotatedDimension Dim2 = DimPloter.AddRotDim(db, ref ext, ptEnd1.Convert3D(), ptEnd.Convert3D(), ptEnd2.Convert3D(5*scale), scale, 90);
                res.Add(Dim2);

                // 标注
                RotatedDimension Dim3 = DimPloter.AddRotDim(db, ref ext, pt.Convert3D(0, -interval1/2 * scale), pt.Convert3D(0, -(interval1 / 2 + interval1) * scale), pt.Convert3D(-5 * scale), scale, 90);
                res.Add(Dim3);

                // 标注
                RotatedDimension Dim6 = DimPloter.AddRotDim(db, ref ext, list[list.Count - 10].Convert3D(), list[list.Count - 8].Convert3D(), list[list.Count - 9].Convert3D(-5*scale), scale, 90);
                res.Add(Dim6);

                // 标注
                RotatedDimension Dim4 = DimPloter.AddRotDim(db, ref ext, ptEnd.Convert3D(), ptEnd.Convert3D(-offsetRadius), ptEnd.Convert3D(0,-5 * scale), scale, 0);
                res.Add(Dim4);

                // 标注
                RotatedDimension Dim5 = DimPloter.AddRotDim(db, ref ext, pt.Convert3D(radius *2* scale), pt.Convert3D(), pt.Convert3D(0, 5 * scale), scale, 0);
                res.Add(Dim5);
                #endregion
                foreach (DBObject drawitem in res)
                {
                    recorder.AppendEntity((Entity)drawitem);
                    tr.AddNewlyCreatedDBObject(drawitem, true);
                }

                tr.Commit();
                ext = ext.Add(new Extents2d(Dim1.Bounds.Value.MinPoint.Convert2D(), Dim1.Bounds.Value.MaxPoint.Convert2D()));
                ext = ext.Add(new Extents2d(Dim2.Bounds.Value.MinPoint.Convert2D(), Dim2.Bounds.Value.MaxPoint.Convert2D()));
                ext = ext.Add(new Extents2d(Dim3.Bounds.Value.MinPoint.Convert2D(), Dim3.Bounds.Value.MaxPoint.Convert2D()));
                ext = ext.Add(new Extents2d(Dim4.Bounds.Value.MinPoint.Convert2D(), Dim4.Bounds.Value.MaxPoint.Convert2D()));
                ext = ext.Add(new Extents2d(Dim5.Bounds.Value.MinPoint.Convert2D(), Dim5.Bounds.Value.MaxPoint.Convert2D()));
                ext = ext.Add(new Extents2d(Dim6.Bounds.Value.MinPoint.Convert2D(), Dim6.Bounds.Value.MaxPoint.Convert2D()));
            }
        }
        public static void CreateSteelBar(Database db, ref Extents2d ext, Point2d pt, double radius,
    double height,double L,double intervalT=100, double intervalL=200, double scale = 100)
        {
            DBObjectCollection res = new DBObjectCollection();
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                #region 螺旋钢筋
                // 螺旋钢筋的拉伸间隔
                //double interval1 = 3;
                //double interval2 = 5;
                Point2d ptEnd1 = Point2d.Origin;
                Point2d ptEnd2 = Point2d.Origin;
                Point2d ptEnd = Point2d.Origin;
                List<Point2d> list = new List<Point2d>();
                Polyline Line = new Polyline() { Closed = false, Layer = "粗线" };
                Line.AddVertexAt(0, pt.Convert2D(-radius), 0, 0, 0);
                Line.AddVertexAt(0, pt.Convert2D(radius), 0, 0, 0);

                list.Add(pt.Convert2D(-radius));
                list.Add(pt.Convert2D(radius ));

                int num1 = (int)(height / intervalT) + 1;
                for (int i = 0; i < num1; ++i)
                {
                    Point2d pt1 = list[list.Count - 1].Convert2D(-radius * 2 , -intervalT / 2 );
                    list.Add(pt1.Convert2D());

                    Point2d pt2 = list[list.Count - 1].Convert2D(radius * 2 , -intervalT / 2 );
                    list.Add(pt2.Convert2D());

                    Line.AddVertexAt(0, pt1, 0, 0, 0);
                    Line.AddVertexAt(0, pt2, 0, 0, 0);
                    if(i == num1-1)
                      ptEnd1 = list[list.Count - 1].Convert2D(radius * 2, -intervalT / 2);
                }

                int num2 = (int)((L-height)/ intervalL);
                int j = 1;
                double offsetRadius = radius;
                for (int i = 0; i < num2; ++i)
                {
                    if ((i == num2 - 1) || (i == num2 - 2) || (i == num2 - 3))
                    {
                        double offset = radius*j/6.0;
                        Line.AddVertexAt(0, list[list.Count - 1].Convert2D(-radius*2  + offset, -intervalL/2), 0, 0, 0);
                        list.Add(list[list.Count - 1].Convert2D(-radius * 2, -intervalL / 2));
                        Line.AddVertexAt(0, list[list.Count - 1].Convert2D(radius * 2 - offset, -intervalL /2), 0, 0, 0);
                        list.Add(list[list.Count - 1].Convert2D(radius * 2, -intervalL/2));
                        //offsetRadius = radius * 2 - 6 * offset;
                        ++j;
                    }
                    else
                    {
                        double offset = intervalL * i + intervalL / 2;
                        if (i == 0)
                        {
                            offset = intervalL / 2;
                        }
                        Point2d pt1 = list[list.Count - 1].Convert2D(-radius * 2 , -intervalL / 2);
                        list.Add(pt1);
                        Line.AddVertexAt(0, pt1, 0, 0, 0);
                        Point2d pt2 = list[list.Count - 1].Convert2D(radius * 2 , -intervalL / 2);
                        list.Add(pt2);
                        Line.AddVertexAt(0, pt2, 0, 0, 0);
                        //ptEnd2 = pt2;
                    }
                }
                double offsetE = radius * 3/ 6.0;
                Line.AddVertexAt(0, list[list.Count - 1].Convert2D(-radius * 2+ offsetE), 0, 0, 0);
                list.Add(list[list.Count - 1].Convert2D(-radius * 2));
                ext = ext.Add(new Extents2d(Line.Bounds.Value.MinPoint.Convert2D(), Line.Bounds.Value.MaxPoint.Convert2D()));
                res.Add(Line);
                #endregion

                //#region 引线
                //// 直线
                //Point2d startPt = pt.Convert2D(radius * 2 * scale * 3 / 4, intervalT / 2 * scale);
                //Polyline pl1 = new Polyline() { Closed = false, Layer = "标注" };
                //pl1.AddVertexAt(0, startPt, 0, 0, 0);
                //pl1.AddVertexAt(0, startPt.Convert2D(10 * scale, 10 * scale), 0, 0, 0);
                //ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.Convert2D(), pl1.Bounds.Value.MaxPoint.Convert2D()));
                //res.Add(pl1);

                //Polyline pl2 = new Polyline() { Closed = false, Layer = "标注" };
                //pl2.AddVertexAt(0, startPt.Convert2D(10 * scale, 10 * scale), 0, 0, 0);
                //pl2.AddVertexAt(0, startPt.Convert2D(10 * scale + 30 * scale, 10 * scale), 0, 0, 0);
                //ext = ext.Add(new Extents2d(pl2.Bounds.Value.MinPoint.Convert2D(), pl2.Bounds.Value.MaxPoint.Convert2D()));
                //res.Add(pl2);

                //// 文字
                //TextPloter.PlotText(db, ref ext, TextPloter.eTxtLocation.E_TOP, startPt.Convert2D(10 * scale + pl2.Length / 2, 11 * scale),
                //    "1T12", scale, Extensions.curFont);

                //TextPloter.PlotText(db, ref ext, TextPloter.eTxtLocation.E_BOTTOM, startPt.Convert2D(10 * scale + pl2.Length / 2, 9 * scale),
                //    "22.7357L+191409", scale, Extensions.curFont);

                //// 圆形标记
                //DimPloter.CircularMark(db, ref ext, startPt.Convert3D(10 * scale + 30 * scale, 10 * scale),
                //    "4a", Extensions.curFont, 10);
                //#endregion

                //#region 标注
                //// 标注
                //RotatedDimension Dim1 = DimPloter.AddRotDim(pt.Convert3D(radius * scale), ptEnd1.Convert3D(), ptEnd1.Convert3D(5 * scale), DimPloter.GetDimStyle(db, (int)scale), 90);
                //res.Add(Dim1);

                //// 标注
                //RotatedDimension Dim2 = DimPloter.AddRotDim(ptEnd1.Convert3D(), ptEnd.Convert3D(), ptEnd2.Convert3D(5 * scale), DimPloter.GetDimStyle(db, (int)scale), 90);
                //res.Add(Dim2);

                //// 标注
                //RotatedDimension Dim3 = DimPloter.AddRotDim(pt.Convert3D(0, -intervalT / 2 * scale), pt.Convert3D(0, -(intervalT / 2 + intervalT) * scale), pt.Convert3D(-5 * scale), DimPloter.GetDimStyle(db, (int)scale), 90);
                //res.Add(Dim3);

                //// 标注
                //RotatedDimension Dim6 = DimPloter.AddRotDim(list[list.Count - 10].Convert3D(), list[list.Count - 8].Convert3D(), list[list.Count - 9].Convert3D(-5 * scale), DimPloter.GetDimStyle(db, (int)scale), 90);
                //res.Add(Dim6);

                //// 标注
                //RotatedDimension Dim4 = DimPloter.AddRotDim(ptEnd.Convert3D(), ptEnd.Convert3D(-offsetRadius), ptEnd.Convert3D(0, -5 * scale), DimPloter.GetDimStyle(db, (int)scale), 0);
                //res.Add(Dim4);

                //// 标注
                //RotatedDimension Dim5 = DimPloter.AddRotDim(pt.Convert3D(radius * 2 * scale), pt.Convert3D(), pt.Convert3D(0, 5 * scale), DimPloter.GetDimStyle(db, (int)scale), 0);
                //res.Add(Dim5);
                //#endregion
                foreach (DBObject drawitem in res)
                {
                    recorder.AppendEntity((Entity)drawitem);
                    tr.AddNewlyCreatedDBObject(drawitem, true);
                }

                tr.Commit();
               
            }
        }

        public static void CreateReinforcedCageTopHalf(Database db, ref Extents2d ext, Point2d pt,
            double radius, int rebarNum, double pileHeight,double scale=100)
        {
            DBObjectCollection res = new DBObjectCollection();
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                //计算每根钢筋的起始坐标
                #region 计算每根钢筋的投影坐标
                double height = 0;
                double width = 0;
                double arcRadius = radius + radius/10*2;          // 弧线半径
                List<Point3d> list = new List<Point3d>();
                list.Add(pt.Convert3D((arcRadius -radius) *scale,0));
                for (int i = 1; i < rebarNum; ++i)
                {
                    // 计算圆点
                    double angle = 360 / rebarNum * i;

                    if (angle > 0 && angle < 90)
                    {
                        angle = GeTools.DegreeToRadian(angle);
                        height = Math.Abs(radius * Math.Sin(angle));
                        width = -Math.Abs(radius * Math.Cos(angle));
                    }
                    else if (angle > 90 && angle < 180)
                    {
                        angle = GeTools.DegreeToRadian(180 - angle);
                        height = Math.Abs( radius * Math.Sin(angle));
                        width = Math.Abs(radius * Math.Cos(angle));
                    }
                    else if (angle > 180 && angle < 270)
                    {
                        angle = GeTools.DegreeToRadian(270 - angle);
                        height = -Math.Abs( radius * Math.Cos(angle));
                        width = Math.Abs( radius * Math.Sin(angle));
                    }
                    else if (angle > 270 && angle < 360)
                    {
                        angle = GeTools.DegreeToRadian(360 - angle);
                        height = -Math.Abs( radius * Math.Sin(angle));
                        width = -Math.Abs(radius * Math.Cos(angle));
                    }
                    else if (angle == 0 || angle == 360)
                    {
                        height = -radius * Math.Sin(0);
                        width = -radius * Math.Cos(0);
                    }
                    else if (angle == 90)
                    {
                        height = radius * Math.Cos(0);
                        width = radius * Math.Sin(0);
                    }
                    else if (angle == 180)
                    {
                        angle = 360 - angle;
                        height = radius * Math.Sin(0);
                        width = radius * Math.Cos(0);
                    }
                    else if (angle == 270)
                    {
                        angle = 360 - angle;
                        height = -radius * Math.Cos(0);
                        width = radius * Math.Sin(0);
                    }

                    Point3d center = pt.Convert3D((arcRadius+width)*scale, 0);
                    list.Add(center);
                }

                list.Sort((a, b) => a.X.CompareTo(b.X));
                // 绘制钢筋投影

                // 绘制弧线
                double startAngle = 60;
                double arcAngle = 60;
                
                Arc arc1 = new Arc(pt.Convert3D(arcRadius*Math.Sin(GeTools.DegreeToRadian(arcAngle / 2))*scale, -pileHeight * scale + arcRadius * scale * Math.Cos(GeTools.DegreeToRadian(arcAngle / 2))), 
                    arcRadius * scale, GeTools.DegreeToRadian(240), GeTools.DegreeToRadian(240 + arcAngle)) { Layer = "细线" };
                ext = ext.Add(new Extents2d(arc1.Bounds.Value.MinPoint.Convert2D(), arc1.Bounds.Value.MaxPoint.Convert2D()));
                res.Add(arc1);

                Arc arc2 = new Arc(pt.Convert3D((arcRadius + arcRadius * Math.Sin(GeTools.DegreeToRadian(arcAngle / 2))) * scale,-(pileHeight+arcRadius*Math.Cos(GeTools.DegreeToRadian(arcAngle/2)))*scale), 
                    arcRadius * scale, GeTools.DegreeToRadian(60), GeTools.DegreeToRadian(60 + arcAngle)) { Layer = "细线" };
                ext = ext.Add(new Extents2d(arc2.Bounds.Value.MinPoint.Convert2D(), arc2.Bounds.Value.MaxPoint.Convert2D()));
                res.Add(arc2);

                Arc arc3 = new Arc(pt.Convert3D((arcRadius + arcRadius * Math.Sin(GeTools.DegreeToRadian(arcAngle / 2))) * scale, -(pileHeight - arcRadius * Math.Cos(GeTools.DegreeToRadian(arcAngle / 2))) * scale), 
                    arcRadius * scale, GeTools.DegreeToRadian(240), GeTools.DegreeToRadian(240 + arcAngle)) { Layer = "细线" };
                ext = ext.Add(new Extents2d(arc3.Bounds.Value.MinPoint.Convert2D(), arc3.Bounds.Value.MaxPoint.Convert2D()));
                res.Add(arc3);

                List<Point3d> listBak = new List<Point3d>();
                Point3dCollection pts = new Point3dCollection();
                for (int i = 0; i < list.Count; ++i)
                {
                    double cosValue = 0;
                    double angle = 0;
                    double sinValue = 0;
                    pts.Clear();
                    Polyline line = new Polyline() { Closed = false, Layer = "粗线" };
                    // 计算垂直钢筋线与弧线的交点
                    if (list[i].X <= arc1.Center.X + arcRadius*scale*Math.Sin(GeTools.DegreeToRadian(arcAngle / 2)))
                    {
                        Polyline l1 = new Polyline();
                        l1.AddVertexAt(0, list[i].Convert2D(), 0, 0, 0);
                        l1.AddVertexAt(0, list[i].Convert2D(0,-pileHeight*2*scale), 0, 0, 0);
                        l1.IntersectWith((Entity)arc1, Intersect.ExtendBoth, pts, IntPtr.Zero, IntPtr.Zero);

                        line.AddVertexAt(0, list[i].Convert2D(), 0, 0, 0);
                        if(list[i].X <= arc1.Center.X)
                        {
                            line.AddVertexAt(0, pts[0].Convert2D(), 0, 0, 0);
                        }
                        else if(arc1.Center.X <= list[i].X && list[i].X <= arc1.Center.X + arcRadius * scale * Math.Sin(GeTools.DegreeToRadian(arcAngle/2)))
                        {
                            line.AddVertexAt(0, pts[1].Convert2D(), 0, 0, 0);
                        }
                    }
                    else if (arc3.Center.X - arcRadius * scale * Math.Sin(GeTools.DegreeToRadian(arcAngle / 2)) <= list[i].X  && list[i].X <= arc3.Center.X + arcRadius*scale* Math.Sin(GeTools.DegreeToRadian(arcAngle / 2)))
                    {
                        Polyline l1 = new Polyline();
                        l1.AddVertexAt(0, list[i].Convert2D(), 0, 0, 0);
                        l1.AddVertexAt(0, list[i].Convert2D(0, -pileHeight * 2 * scale), 0, 0, 0);
                        l1.IntersectWith((Entity)arc2, Intersect.ExtendBoth, pts, IntPtr.Zero, IntPtr.Zero);

                        line.AddVertexAt(0, list[i].Convert2D(), 0, 0, 0);
                        if(list[i].X <= arc3.Center.X)
                        {
                            line.AddVertexAt(0, pts[1].Convert2D(), 0, 0, 0);
                        }
                        else if(list[i].X >= arc3.Center.X && arc3.Center.X <= arc3.Center.X+arcRadius*scale*Math.Sin(GeTools.DegreeToRadian(arcAngle/2)))
                        {
                            line.AddVertexAt(0, pts[0].Convert2D(), 0, 0, 0);
                        }
                    }
                    if (line.Bounds != null)
                    {
                        ext = ext.Add(new Extents2d(line.Bounds.Value.MinPoint.Convert2D(), line.Bounds.Value.MaxPoint.Convert2D()));
                        res.Add(line);
                    }
                }

                // 计算横向钢筋线与弧线的交叉线
                double sinSide = 0;
                double sinAngle = 0;
                double cosSide = 0;
                for (int i = 0; i < (int)(Math.Abs((list[0].Y - (arc3.Center.Y - arcRadius))) / scale); ++i)
                {
                    Polyline line2 = new Polyline() { Closed = false, Layer = "粗线" };
                    Polyline line3 = new Polyline() { Closed = false, Layer = "粗线" };
                    if ((pt.Y - scale * (i + 1) >= arc3.Center.Y - arcRadius) && (pt.Y - scale * (i + 1) <= list[0].Y))
                    {
                        if ((list[0].Y - scale * (i + 1)) <= (arc1.Center.Y + arcRadius) &&
                            (list[0].Y - scale * (i + 1)) >= arc1.Center.Y + arcRadius * Math.Cos(GeTools.DegreeToRadian(arcAngle / 2)))
                        {
                            //左边弧形交点计算
                            sinAngle = GeTools.RadianToDegree(Math.Asin(Math.Abs(arc1.Center.Y - list[0].Y + scale * (i + 1)) / arcRadius));
                            cosSide = arcRadius * Math.Cos(GeTools.DegreeToRadian(sinAngle));
                            sinSide = arcRadius * Math.Sin(GeTools.DegreeToRadian(sinAngle));
                            line2.AddVertexAt(0, list[0].Convert2D(-scale / 2, -scale * (i + 1)), 0, 0, 0);
                            line2.AddVertexAt(1, arc1.Center.Convert2D(-cosSide, sinSide), 0, 0, 0);
                            ext = ext.Add(new Extents2d(line2.Bounds.Value.MinPoint.Convert2D(), line2.Bounds.Value.MaxPoint.Convert2D()));
                            //res.Add(line2);

                            line3.AddVertexAt(0, arc1.Center.Convert2D(cosSide, sinSide), 0, 0, 0);
                            line3.AddVertexAt(1, list[list.Count - 1].Convert2D(scale / 2, -scale * (i + 1)), 0, 0, 0);
                            ext = ext.Add(new Extents2d(line3.Bounds.Value.MinPoint.Convert2D(), line3.Bounds.Value.MaxPoint.Convert2D()));
                            //res.Add(line3);
                        }
                        else if ((list[0].Y - scale * (i + 1)) >= (arc3.Center.Y - arcRadius) &&
                            (list[0].Y - scale * (i + 1)) <= arc3.Center.Y - arcRadius * Math.Cos(GeTools.DegreeToRadian(arcAngle / 2)))
                        {
                            //右边弧形交点计算
                            sinAngle = GeTools.RadianToDegree(Math.Asin(Math.Abs(arc3.Center.Y - list[0].Y + scale * (i + 1)) / arcRadius));
                            cosSide = arcRadius * Math.Cos(GeTools.DegreeToRadian(sinAngle));
                            sinSide = arcRadius * Math.Sin(GeTools.DegreeToRadian(sinAngle));
                            line2.AddVertexAt(0, arc3.Center.Convert2D(-cosSide, -sinSide), 0, 0, 0);
                            line2.AddVertexAt(1, arc3.Center.Convert2D(cosSide, -sinSide), 0, 0, 0);
                            ext = ext.Add(new Extents2d(line2.Bounds.Value.MinPoint.Convert2D(), line2.Bounds.Value.MaxPoint.Convert2D()));
                            //res.Add(line2);

                            line3.AddVertexAt(0, arc1.Center.Convert2D(cosSide, -sinSide), 0, 0, 0);
                            line3.AddVertexAt(1, list[list.Count - 1].Convert2D(scale / 2, -scale * (i + 1)), 0, 0, 0);
                            ext = ext.Add(new Extents2d(line3.Bounds.Value.MinPoint.Convert2D(), line3.Bounds.Value.MaxPoint.Convert2D()));
                            //res.Add(line3);
                        }
                        else
                        {
                            // 无交点
                            line2.AddVertexAt(0, list[0].Convert2D(-scale / 2, -scale * (i + 1)), 0, 0, 0);
                            line2.AddVertexAt(0, list[list.Count - 1].Convert2D(scale / 2, -scale * (i + 1)), 0, 0, 0);
                            ext = ext.Add(new Extents2d(line2.Bounds.Value.MinPoint.Convert2D(), line2.Bounds.Value.MaxPoint.Convert2D()));
                            //res.Add(line2);
                        }
                    }
                }
                #endregion

                #region 绘制边框线
                // 计算两边线的坐标
                double cosHeight = arcRadius * Math.Cos(GeTools.DegreeToRadian(arcAngle / 2));
                Point2d leftPt = arc1.Center.Convert2D(- arcRadius * scale * Math.Sin(GeTools.DegreeToRadian(arcAngle / 2)), -arcRadius * scale * Math.Cos(GeTools.DegreeToRadian(arcAngle / 2)));
                Point2d rightPt = arc3.Center.Convert2D(arcRadius * scale * Math.Sin(GeTools.DegreeToRadian(arcAngle / 2)), -arcRadius * scale * Math.Cos(GeTools.DegreeToRadian(arcAngle / 2)));
                Polyline line6 = new Polyline() { Closed = false, Layer = "粗线" };
                Point2d pt6 = leftPt.Convert2D(0, pileHeight * 0.8*scale);
                Point2d pt7 = pt6.Convert2D(arcRadius*2*scale);
                line6.AddVertexAt(0, leftPt, 0, 0, 0);
                line6.AddVertexAt(1, pt6, 0, 0, 0);
                line6.AddVertexAt(2, pt7, 0, 0, 0);
                line6.AddVertexAt(3, rightPt, 0, 0, 0);
                ext = ext.Add(new Extents2d(line6.Bounds.Value.MinPoint.Convert2D(), line6.Bounds.Value.MaxPoint.Convert2D()));
                res.Add(line6);

                // 上部边框
                Polyline line7 = new Polyline() { Closed = false, Layer = "粗线" };
                Point2d line71 = pt6.Convert2D(0,-2*scale);
                Point2d line72 = line71.Convert2D(-20*scale);
                Point2d line73 = line72.Convert2D(0,pileHeight*0.1*scale);
                Point2d line74 = line73.Convert2D(-2*scale, scale);
                Point2d line75 = line74.Convert2D(4 * scale, 2*scale);
                Point2d line76 = line75.Convert2D(-2 * scale, scale);
                Point2d line78 = line76.Convert2D(0, pileHeight * 0.1 * scale);
                Point2d line79 = line78.Convert2D(40*scale+ rightPt.X-leftPt.X);
                Point2d line80 = line79.Convert2D(0,-pileHeight * 0.1 * scale);
                Point2d line81 = line80.Convert2D(2 * scale,-scale);
                Point2d line82 = line81.Convert2D(-4 * scale, -2*scale);
                Point2d line83 = line82.Convert2D(2 * scale, -scale);
                Point2d line84 = line83.Convert2D(0,-pileHeight * 0.1 * scale);
                Point2d line85 = pt7.Convert2D(0,-2*scale);

                line7.AddVertexAt(0, line71, 0, 0, 0);
                line7.AddVertexAt(0, line72, 0, 0, 0);
                line7.AddVertexAt(0, line73, 0, 0, 0);
                line7.AddVertexAt(0, line74, 0, 0, 0);
                line7.AddVertexAt(0, line75, 0, 0, 0);
                line7.AddVertexAt(0, line76, 0, 0, 0);
                line7.AddVertexAt(0, line78, 0, 0, 0);
                line7.AddVertexAt(0, line79, 0, 0, 0);
                line7.AddVertexAt(0, line80, 0, 0, 0);
                line7.AddVertexAt(0, line81, 0, 0, 0);
                line7.AddVertexAt(0, line82, 0, 0, 0);
                line7.AddVertexAt(0, line83, 0, 0, 0);
                line7.AddVertexAt(0, line84, 0, 0, 0);
                line7.AddVertexAt(0, line85, 0, 0, 0);
                ext = ext.Add(new Extents2d(line7.Bounds.Value.MinPoint.Convert2D(), line7.Bounds.Value.MaxPoint.Convert2D()));
                res.Add(line7);
                #endregion

                #region 螺旋钢筋
                // 螺旋钢筋的拉伸间隔
                double interval1 = 3;
                double interval2 = 5;
                Point2d ptEnd1 = Point2d.Origin;
                Point2d ptEnd2 = Point2d.Origin;
                Point2d ptEnd = Point2d.Origin;
                List<Point2d> listSpiral = new List<Point2d>();
                Polyline Line = new Polyline() { Closed = false, Layer = "粗线" };
                Line.AddVertexAt(0, leftPt.Convert2D((arcRadius - radius) * scale, pileHeight*0.8*scale), 0, 0, 0);
                Line.AddVertexAt(0, leftPt.Convert2D((arcRadius + radius) * scale, pileHeight * 0.8*scale), 0, 0, 0);

                listSpiral.Add(leftPt.Convert2D((arcRadius-radius)*scale, pileHeight * 0.8*scale));
                listSpiral.Add(leftPt.Convert2D((arcRadius + radius) * scale, pileHeight * 0.8*scale));

                height = pileHeight * 0.8;
                int num1 = (int)(height *0.7 / interval1) + 1;
                for (int i = 0; i < num1; ++i)
                {
                    Point2d pt1 = listSpiral[listSpiral.Count - 1].Convert2D(-radius * 2 * scale, -interval1 / 2 * scale);
                    listSpiral.Add(pt1.Convert2D());

                    Point2d pt2 = listSpiral[listSpiral.Count - 1].Convert2D(radius * 2 * scale, -interval1 / 2 * scale);
                    listSpiral.Add(pt2.Convert2D());

                    Line.AddVertexAt(0, pt1, 0, 0, 0);
                    Line.AddVertexAt(0, pt2, 0, 0, 0);
                    ptEnd1 = listSpiral[listSpiral.Count - 1].Convert2D();
                }

                int num2 = (int)(height * 0.3 / interval2);
                int j = 1;
                double offsetRadius = radius;
                for (int i = 0; i < num2; ++i)
                {
                    double offset = interval2 * i + interval2 / 2;
                    if (i == 0)
                    {
                        offset = interval2 / 2;
                    }
                    Point2d pt1 = ptEnd1.Convert2D(-radius * 2 * scale, -offset * scale);
                    listSpiral.Add(pt1);
                    //Line.AddVertexAt(0, pt1, 0, 0, 0);
                    Point2d pt2 = listSpiral[listSpiral.Count - 1].Convert2D(radius * 2 * scale, -interval2);
                    listSpiral.Add(pt2);
                    //Line.AddVertexAt(0, pt2, 0, 0, 0);

                    Polyline pl = new Polyline() { Closed = false, Layer = "粗线" };
                    pl.AddVertexAt(0, pt1, 0, 0, 0);
                    pl.AddVertexAt(0, pt2, 0, 0, 0);
                    pts.Clear();
                    pl.IntersectWith((Entity)arc2, Intersect.ExtendBoth, pts, IntPtr.Zero, IntPtr.Zero);
                    if(pts!= null && pts.Count > 0)
                    {
                        Line.AddVertexAt(0, pt1, 0, 0, 0);
                        Line.AddVertexAt(0, pts[0].Convert2D(), 0, 0, 0);

                        //Line.AddVertexAt(0, pts[1].Convert2D(), 0, 0, 0);
                        //Line.AddVertexAt(0, pt2, 0, 0, 0);
                    }
                    else
                    {
                        Line.AddVertexAt(0, pt1, 0, 0, 0);
                        Line.AddVertexAt(0, pt2, 0, 0, 0);
                    }
                    ptEnd2 = pt2;
                }

                ext = ext.Add(new Extents2d(Line.Bounds.Value.MinPoint.Convert2D(), Line.Bounds.Value.MaxPoint.Convert2D()));
                res.Add(Line);
                #endregion

                #region 上部平直钢筋
                int num = (int)(pileHeight * 0.2 / 2.5);
                for(int i = 0; i < num;++i)
                {
                    Polyline pl = new Polyline() { Closed = false, Layer = "粗线" };
                    pl.AddVertexAt(0, list[0].Convert2D(-2.5 * scale, -2.5 * scale * (i + 1)), 0, 0, 0);
                    pl.AddVertexAt(0, list[0].Convert2D(radius*scale*2+ 2.5 * scale, -2.5*scale*(i+1)),0,0,0);

                    ext = ext.Add(new Extents2d(pl.Bounds.Value.MinPoint.Convert2D(), pl.Bounds.Value.MaxPoint.Convert2D()));
                    res.Add(pl);
                }
                #endregion

                #region 固定件
                // 左边
                double w1 = radius / 10 *scale/*scale / 2 * scale*/;

                Point2d fixedPt1 = list[0].Convert2D(0, -pileHeight*scale*0.2-30*scale);
                Polyline plFixedPart1 = new Polyline() { Closed = false, Layer = "粗线", LinetypeScale = 3, LineWeight = LineWeight.LineWeight100 };
                plFixedPart1.AddVertexAt(0, fixedPt1.Convert2D(0, 15 * scale), 0, 0, 0);
                plFixedPart1.AddVertexAt(0, fixedPt1.Convert2D(0, 10 * scale), 0, 0, 0);
                plFixedPart1.AddVertexAt(0, fixedPt1.Convert2D(-w1, 5 * scale), 0, 0, 0);
                plFixedPart1.AddVertexAt(0, fixedPt1.Convert2D(-w1, -5 * scale), 0, 0, 0);
                plFixedPart1.AddVertexAt(0, fixedPt1.Convert2D(0, -10 * scale), 0, 0, 0);
                plFixedPart1.AddVertexAt(0, fixedPt1.Convert2D(0, 15 * scale), 0, 0, 0);
                ext = ext.Add(new Extents2d(plFixedPart1.Bounds.Value.MinPoint.Convert2D(), plFixedPart1.Bounds.Value.MaxPoint.Convert2D()));
                res.Add(plFixedPart1);

                Point2d fixedPt2 = list[0].Convert2D(0, -pileHeight * scale * 0.2 - 70 * scale);
                Polyline plFixedPart2 = new Polyline() { Closed = false, Layer = "粗线", LinetypeScale = 3, LineWeight = LineWeight.LineWeight100 };
                plFixedPart2.AddVertexAt(0, fixedPt2.Convert2D(0, 15 * scale), 0, 0, 0);
                plFixedPart2.AddVertexAt(0, fixedPt2.Convert2D(0, 10 * scale), 0, 0, 0);
                plFixedPart2.AddVertexAt(0, fixedPt2.Convert2D(-w1, 5 * scale), 0, 0, 0);
                plFixedPart2.AddVertexAt(0, fixedPt2.Convert2D(-w1, -5 * scale), 0, 0, 0);
                plFixedPart2.AddVertexAt(0, fixedPt2.Convert2D(0, -10 * scale), 0, 0, 0);
                plFixedPart2.AddVertexAt(0, fixedPt2.Convert2D(0, 15 * scale), 0, 0, 0);
                ext = ext.Add(new Extents2d(plFixedPart2.Bounds.Value.MinPoint.Convert2D(), plFixedPart2.Bounds.Value.MaxPoint.Convert2D()));
                res.Add(plFixedPart2);

                Point2d fixedPt3 = list[0].Convert2D(0, -pileHeight * scale * 0.2 - 110 * scale);
                Polyline plFixedPart3 = new Polyline() { Closed = false, Layer = "粗线", LinetypeScale = 3, LineWeight = LineWeight.LineWeight100 };
                plFixedPart3.AddVertexAt(0, fixedPt3.Convert2D(0, 15 * scale), 0, 0, 0);
                plFixedPart3.AddVertexAt(0, fixedPt3.Convert2D(0, 10 * scale), 0, 0, 0);
                plFixedPart3.AddVertexAt(0, fixedPt3.Convert2D(-w1, 5 * scale), 0, 0, 0);
                plFixedPart3.AddVertexAt(0, fixedPt3.Convert2D(-w1, -5 * scale), 0, 0, 0);
                plFixedPart3.AddVertexAt(0, fixedPt3.Convert2D(0, -10 * scale), 0, 0, 0);
                plFixedPart3.AddVertexAt(0, fixedPt3.Convert2D(0, 15 * scale), 0, 0, 0);
                ext = ext.Add(new Extents2d(plFixedPart3.Bounds.Value.MinPoint.Convert2D(), plFixedPart3.Bounds.Value.MaxPoint.Convert2D()));
                res.Add(plFixedPart3);

                Point2d fixedPt4 = list[0].Convert2D(0, -pileHeight * scale * 0.2 - 150 * scale);
                Polyline plFixedPart4 = new Polyline() { Closed = false, Layer = "粗线", LinetypeScale = 3, LineWeight = LineWeight.LineWeight100 };
                plFixedPart4.AddVertexAt(0, fixedPt4.Convert2D(0, 15 * scale), 0, 0, 0);
                plFixedPart4.AddVertexAt(0, fixedPt4.Convert2D(0, 10 * scale), 0, 0, 0);
                plFixedPart4.AddVertexAt(0, fixedPt4.Convert2D(-w1, 5 * scale), 0, 0, 0);
                plFixedPart4.AddVertexAt(0, fixedPt4.Convert2D(-w1, -5 * scale), 0, 0, 0);
                plFixedPart4.AddVertexAt(0, fixedPt4.Convert2D(0, -10 * scale), 0, 0, 0);
                plFixedPart4.AddVertexAt(0, fixedPt4.Convert2D(0, 15 * scale), 0, 0, 0);
                ext = ext.Add(new Extents2d(plFixedPart4.Bounds.Value.MinPoint.Convert2D(), plFixedPart4.Bounds.Value.MaxPoint.Convert2D()));
                res.Add(plFixedPart4);

                Point2d fixedPt5 = list[0].Convert2D(0, -pileHeight * scale * 0.2 - 190 * scale);
                Polyline plFixedPart5 = new Polyline() { Closed = false, Layer = "粗线", LinetypeScale = 3, LineWeight = LineWeight.LineWeight100 };
                plFixedPart5.AddVertexAt(0, fixedPt5.Convert2D(0, 15 * scale), 0, 0, 0);
                plFixedPart5.AddVertexAt(0, fixedPt5.Convert2D(0, 10 * scale), 0, 0, 0);
                plFixedPart5.AddVertexAt(0, fixedPt5.Convert2D(-w1, 5 * scale), 0, 0, 0);
                plFixedPart5.AddVertexAt(0, fixedPt5.Convert2D(-w1, -5 * scale), 0, 0, 0);
                plFixedPart5.AddVertexAt(0, fixedPt5.Convert2D(0, -10 * scale), 0, 0, 0);
                plFixedPart5.AddVertexAt(0, fixedPt5.Convert2D(0, 15 * scale), 0, 0, 0);
                ext = ext.Add(new Extents2d(plFixedPart5.Bounds.Value.MinPoint.Convert2D(), plFixedPart5.Bounds.Value.MaxPoint.Convert2D()));
                res.Add(plFixedPart5);

                // 右边
                Point2d fixedPt6 = list[list.Count-1].Convert2D(0, -pileHeight * scale * 0.2 - 30 * scale);
                Polyline plFixedPart6 = new Polyline() { Closed = false, Layer = "粗线", LinetypeScale = 3, LineWeight = LineWeight.LineWeight100 };
                plFixedPart6.AddVertexAt(0, fixedPt6.Convert2D(0, 15 * scale), 0, 0, 0);
                plFixedPart6.AddVertexAt(0, fixedPt6.Convert2D(0, 10 * scale), 0, 0, 0);
                plFixedPart6.AddVertexAt(0, fixedPt6.Convert2D(w1, 5 * scale), 0, 0, 0);
                plFixedPart6.AddVertexAt(0, fixedPt6.Convert2D(w1, -5 * scale), 0, 0, 0);
                plFixedPart6.AddVertexAt(0, fixedPt6.Convert2D(0, -10 * scale), 0, 0, 0);
                plFixedPart6.AddVertexAt(0, fixedPt6.Convert2D(0, 15 * scale), 0, 0, 0);
                ext = ext.Add(new Extents2d(plFixedPart6.Bounds.Value.MinPoint.Convert2D(), plFixedPart6.Bounds.Value.MaxPoint.Convert2D()));
                res.Add(plFixedPart6);

                Point2d fixedPt7 = list[list.Count - 1].Convert2D(0, -pileHeight * scale * 0.2 - 70 * scale);
                Polyline plFixedPart7 = new Polyline() { Closed = false, Layer = "粗线", LinetypeScale = 3, LineWeight = LineWeight.LineWeight100 };
                plFixedPart7.AddVertexAt(0, fixedPt7.Convert2D(0, 15 * scale), 0, 0, 0);
                plFixedPart7.AddVertexAt(0, fixedPt7.Convert2D(0, 10 * scale), 0, 0, 0);
                plFixedPart7.AddVertexAt(0, fixedPt7.Convert2D(w1, 5 * scale), 0, 0, 0);
                plFixedPart7.AddVertexAt(0, fixedPt7.Convert2D(w1, -5 * scale), 0, 0, 0);
                plFixedPart7.AddVertexAt(0, fixedPt7.Convert2D(0, -10 * scale), 0, 0, 0);
                plFixedPart7.AddVertexAt(0, fixedPt7.Convert2D(0, 15 * scale), 0, 0, 0);
                ext = ext.Add(new Extents2d(plFixedPart7.Bounds.Value.MinPoint.Convert2D(), plFixedPart7.Bounds.Value.MaxPoint.Convert2D()));
                res.Add(plFixedPart7);

                Point2d fixedPt8 = list[list.Count - 1].Convert2D(0, -pileHeight * scale * 0.2 - 110 * scale);
                Polyline plFixedPart8 = new Polyline() { Closed = false, Layer = "粗线", LinetypeScale = 3, LineWeight = LineWeight.LineWeight100 };
                plFixedPart8.AddVertexAt(0, fixedPt8.Convert2D(0, 15 * scale), 0, 0, 0);
                plFixedPart8.AddVertexAt(0, fixedPt8.Convert2D(0, 10 * scale), 0, 0, 0);
                plFixedPart8.AddVertexAt(0, fixedPt8.Convert2D(w1, 5 * scale), 0, 0, 0);
                plFixedPart8.AddVertexAt(0, fixedPt8.Convert2D(w1, -5 * scale), 0, 0, 0);
                plFixedPart8.AddVertexAt(0, fixedPt8.Convert2D(0, -10 * scale), 0, 0, 0);
                plFixedPart8.AddVertexAt(0, fixedPt8.Convert2D(0, 15 * scale), 0, 0, 0);
                ext = ext.Add(new Extents2d(plFixedPart8.Bounds.Value.MinPoint.Convert2D(), plFixedPart8.Bounds.Value.MaxPoint.Convert2D()));
                res.Add(plFixedPart8);

                Point2d fixedPt9 = list[list.Count - 1].Convert2D(0, -pileHeight * scale * 0.2 - 150 * scale);
                Polyline plFixedPart9 = new Polyline() { Closed = false, Layer = "粗线", LinetypeScale = 3, LineWeight = LineWeight.LineWeight100 };
                plFixedPart9.AddVertexAt(0, fixedPt9.Convert2D(0, 15 * scale), 0, 0, 0);
                plFixedPart9.AddVertexAt(0, fixedPt9.Convert2D(0, 10 * scale), 0, 0, 0);
                plFixedPart9.AddVertexAt(0, fixedPt9.Convert2D(w1, 5 * scale), 0, 0, 0);
                plFixedPart9.AddVertexAt(0, fixedPt9.Convert2D(w1, -5 * scale), 0, 0, 0);
                plFixedPart9.AddVertexAt(0, fixedPt9.Convert2D(0, -10 * scale), 0, 0, 0);
                plFixedPart9.AddVertexAt(0, fixedPt9.Convert2D(0, 15 * scale), 0, 0, 0);
                ext = ext.Add(new Extents2d(plFixedPart9.Bounds.Value.MinPoint.Convert2D(), plFixedPart9.Bounds.Value.MaxPoint.Convert2D()));
                res.Add(plFixedPart9);

                Point2d fixedPt10 = list[list.Count - 1].Convert2D(0, -pileHeight * scale * 0.2 - 190 * scale);
                Polyline plFixedPart10 = new Polyline() { Closed = false, Layer = "粗线", LinetypeScale = 3, LineWeight = LineWeight.LineWeight100 };
                plFixedPart10.AddVertexAt(0, fixedPt10.Convert2D(0, 15 * scale), 0, 0, 0);
                plFixedPart10.AddVertexAt(0, fixedPt10.Convert2D(0, 10 * scale), 0, 0, 0);
                plFixedPart10.AddVertexAt(0, fixedPt10.Convert2D(w1, 5 * scale), 0, 0, 0);
                plFixedPart10.AddVertexAt(0, fixedPt10.Convert2D(w1, -5 * scale), 0, 0, 0);
                plFixedPart10.AddVertexAt(0, fixedPt10.Convert2D(0, -10 * scale), 0, 0, 0);
                plFixedPart10.AddVertexAt(0, fixedPt10.Convert2D(0, 15 * scale), 0, 0, 0);
                ext = ext.Add(new Extents2d(plFixedPart10.Bounds.Value.MinPoint.Convert2D(), plFixedPart10.Bounds.Value.MaxPoint.Convert2D()));
                res.Add(plFixedPart10);
                #endregion

                #region 标注
                RotatedDimension Dim1 = DimPloter.AddRotDim(db, ref ext, list[0].Convert3D(), pt6.Convert3D(), list[0].Convert3D(-30*scale),scale, 90);
                res.Add(Dim1);

                RotatedDimension Dim2 = DimPloter.AddRotDim(db, ref ext, line71.Convert3D(), pt6.Convert3D(), list[0].Convert3D(-30 * scale), scale, 90);
                res.Add(Dim2);

                RotatedDimension Dim3 = DimPloter.AddRotDim(db, ref ext, list[0].Convert3D(), pt7.Convert3D(), pt7.Convert3D(10 * scale), scale, 90);
                res.Add(Dim3);

                //RotatedDimension Dim4 = DimPloter.AddRotDim(list[0].Convert3D(), pt7.Convert3D(), pt7.Convert3D(10 * scale), DimPloter.GetDimStyle(db, (int)scale), 90);
                //res.Add(Dim4);
                #endregion
                //var TX1 = Matrix3d.Rotation(GeTools.DegreeToRadian(rotation), Vector3d.ZAxis, pt.Convert3D(radius,-30*scale));
                //foreach (DBObject item in res)
                //{
                //    Entity pr = (Entity)item;
                //    pr.TransformBy(TX1);
                //}

                foreach (DBObject drawitem in res)
                {
                    recorder.AppendEntity((Entity)drawitem);
                    tr.AddNewlyCreatedDBObject(drawitem, true);
                }
                tr.Commit();
            }
        }

        public static void CreateReinforcedCageBottomHalf(Database db, ref Extents2d ext, Point2d pt,
            double radius, double height,double rebarNum, double scale = 100)
        {
            DBObjectCollection res = new DBObjectCollection();
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                #region 圆弧
                double arcAngle = 60;
                double cosH = radius * Math.Cos(GeTools.DegreeToRadian(arcAngle / 2));
                // 绘制弧线
                Arc arc1 = new Arc(pt.Convert3D(radius/2 * scale, -cosH * scale), radius * scale, GeTools.DegreeToRadian(60), GeTools.DegreeToRadian(60 + arcAngle)) { Layer = "细线" };
                ext = ext.Add(new Extents2d(arc1.Bounds.Value.MinPoint.Convert2D(), arc1.Bounds.Value.MaxPoint.Convert2D()));
                res.Add(arc1);

                Arc arc2 = new Arc(pt.Convert3D((radius + radius / 2) * scale, -cosH * scale), radius * scale, GeTools.DegreeToRadian(60), GeTools.DegreeToRadian(60 + arcAngle)) { Layer = "细线" };
                ext = ext.Add(new Extents2d(arc2.Bounds.Value.MinPoint.Convert2D(), arc2.Bounds.Value.MaxPoint.Convert2D()));
                res.Add(arc2);

                Arc arc3 = new Arc(pt.Convert3D(radius/2 * scale, cosH * scale), radius * scale, GeTools.DegreeToRadian(240), GeTools.DegreeToRadian(240 + arcAngle)) { Layer = "细线" };
                ext = ext.Add(new Extents2d(arc3.Bounds.Value.MinPoint.Convert2D(), arc3.Bounds.Value.MaxPoint.Convert2D()));
                res.Add(arc3);
                #endregion

                #region 圆柱
                Polyline pl1 = new Polyline() { Closed = false, Layer = "粗线" };
                pl1.AddVertexAt(0,pt,0,0,0);
                pl1.AddVertexAt(0, pt.Convert2D(0,-height*scale), 0, 0, 0);
                pl1.AddVertexAt(0, pt.Convert2D(radius*2 * scale, -height * scale), 0, 0, 0);
                pl1.AddVertexAt(0, pt.Convert2D(radius * 2 * scale), 0, 0, 0);
                ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.Convert2D(), pl1.Bounds.Value.MaxPoint.Convert2D()));
                res.Add(pl1);
                #endregion

                #region 螺旋钢筋
                // 计算弧线最低位置坐标
                double arcHeight = radius - radius * Math.Cos(GeTools.DegreeToRadian(30));

                // 螺旋钢筋的拉伸间隔
                double spiralRadius = radius - radius * 0.1;
                //radius = radius - radius * 0.2;
                pt = pt.Convert2D(radius*0.1*scale, -arcHeight*scale);
                double interval = radius/10;

                Point2d ptEnd = pt;
                List<Point2d> list = new List<Point2d>();
                Polyline Line = new Polyline() { Closed = false, Layer = "粗线" };
                int num = (int)((height- arcHeight) / interval);
                int j = 1;
                double offsetRadius = radius;
                Line.AddVertexAt(0, pt.Convert2D(), 0, 0, 0);
                Line.AddVertexAt(0, pt.Convert2D(spiralRadius * 2 * scale), 0, 0, 0);
                list.Add(pt.Convert2D());
                list.Add(pt.Convert2D(spiralRadius * 2*scale));

                for (int i = 0; i < num; ++i)
                {
                    if ((i == num - 1) || (i == num - 2) || (i == num - 3))
                    {
                        double offset = radius*0.2;
                        Line.AddVertexAt(0, ptEnd.Convert2D(-spiralRadius * 2 * scale + offset * j, -interval * j * scale), 0, 0, 0);
                        Line.AddVertexAt(0, ptEnd.Convert2D(-j * offset, -interval * scale * j), 0, 0, 0);

                        list.Add(ptEnd.Convert2D(-spiralRadius * 2 * scale + offset * j, -interval * j * scale));
                        list.Add(ptEnd.Convert2D(-j * offset, -interval * scale * j));
                        //ptEnd = ptEnd.Convert2D(-j * offset, -interval * scale * j);
                        offsetRadius = spiralRadius * 2 * scale - 6 * offset;
                        ++j;
                    }
                    else
                    {

                        Point2d pt1 = list[list.Count - 1].Convert2D(-spiralRadius * 2 * scale, -interval / 2 * scale);
                        list.Add(pt1.Convert2D());

                        Point2d pt2 = list[list.Count - 1].Convert2D(spiralRadius * 2 * scale, -interval / 2 * scale);
                        list.Add(pt2.Convert2D());

                        Line.AddVertexAt(0, pt1, 0, 0, 0);
                        Line.AddVertexAt(0, pt2, 0, 0, 0);
                        ptEnd = pt.Convert2D(spiralRadius * 2 * scale, -interval * scale * (i + 1));
                    }
                }

                Line.AddVertexAt(0, list[list.Count-1].Convert2D(-offsetRadius), 0, 0, 0);
                list.Add(ptEnd.Convert2D(-offsetRadius));
                ext = ext.Add(new Extents2d(Line.Bounds.Value.MinPoint.Convert2D(), Line.Bounds.Value.MaxPoint.Convert2D()));
                res.Add(Line);

                #endregion

                #region 计算直线与弧线的交点
                Point3dCollection pts = new Point3dCollection();

                // 直线
                Polyline pL1 = new Polyline() { Closed = false, Layer = "粗线" };
                pL1.AddVertexAt(0,list[0].Convert2D(),0,0,0);
                pL1.AddVertexAt(0, list[0].Convert2D(radius*2*scale, interval*scale), 0, 0, 0);
                //ext = ext.Add(new Extents2d(pL1.Bounds.Value.MinPoint.Convert2D(), pL1.Bounds.Value.MaxPoint.Convert2D()));
                //res.Add(pL1);

                Polyline pL2 = new Polyline() { Closed = false, Layer = "粗线" };
                pL2.AddVertexAt(0, list[0].Convert2D(radius * 2 * scale, interval * scale), 0, 0, 0);
                pL2.AddVertexAt(0, list[0].Convert2D(0, interval * scale), 0, 0, 0);
                //ext = ext.Add(new Extents2d(pL2.Bounds.Value.MinPoint.Convert2D(), pL2.Bounds.Value.MaxPoint.Convert2D()));
                //res.Add(pL2);

                Polyline pL3 = new Polyline() { Closed = false, Layer = "粗线" };
                pL3.AddVertexAt(0, list[0].Convert2D(0, interval * scale), 0, 0, 0);
                pL3.AddVertexAt(0, list[0].Convert2D(radius * 2 * scale, interval * scale * 2), 0, 0, 0);
                //ext = ext.Add(new Extents2d(pL3.Bounds.Value.MinPoint.Convert2D(), pL3.Bounds.Value.MaxPoint.Convert2D()));
                //res.Add(pL3);

                Polyline pL4 = new Polyline() { Closed = false, Layer = "粗线" };
                pL4.AddVertexAt(0, list[0].Convert2D(radius * 2 * scale, interval * scale * 2), 0, 0, 0);
                pL4.AddVertexAt(0, list[0].Convert2D(0, interval * scale * 3), 0, 0, 0);
                //ext = ext.Add(new Extents2d(pL4.Bounds.Value.MinPoint.Convert2D(), pL4.Bounds.Value.MaxPoint.Convert2D()));
                //res.Add(pL4);


                // 直线与弧线arc2的交点
                pL1.IntersectWith((Entity)arc3, Intersect.ExtendBoth, pts, IntPtr.Zero, IntPtr.Zero);
                if (pts != null && pts.Count > 1)
                {
                    Polyline pL5 = new Polyline() { Closed = false, Layer = "粗线" };
                    pL5.AddVertexAt(0, list[0].Convert2D(), 0, 0, 0);
                    pL5.AddVertexAt(0, pts[1].Convert2D(), 0, 0, 0);
                    ext = ext.Add(new Extents2d(pL5.Bounds.Value.MinPoint.Convert2D(), pL5.Bounds.Value.MaxPoint.Convert2D()));
                    res.Add(pL5);

                    Polyline pL6 = new Polyline() { Closed = false, Layer = "粗线" };
                    pL6.AddVertexAt(0, pts[0].Convert2D(), 0, 0, 0);
                    pL6.AddVertexAt(0, list[0].Convert2D(radius * 2 * scale, interval * scale), 0, 0, 0);
                    ext = ext.Add(new Extents2d(pL6.Bounds.Value.MinPoint.Convert2D(), pL6.Bounds.Value.MaxPoint.Convert2D()));
                    res.Add(pL6);
                }

                pts.Clear();
                pL2.IntersectWith((Entity)arc3, Intersect.ExtendBoth, pts, IntPtr.Zero, IntPtr.Zero);
                if (pts != null && pts.Count > 0)
                {
                    Polyline pL5 = new Polyline() { Closed = false, Layer = "粗线" };
                    pL5.AddVertexAt(0, pts[0].Convert2D(), 0, 0, 0);
                    pL5.AddVertexAt(0, list[0].Convert2D(radius * 2 * scale, interval * scale), 0, 0, 0);
                    ext = ext.Add(new Extents2d(pL5.Bounds.Value.MinPoint.Convert2D(), pL5.Bounds.Value.MaxPoint.Convert2D()));
                    res.Add(pL5);
                }

                pts.Clear();
                pL3.IntersectWith((Entity)arc3, Intersect.ExtendBoth, pts, IntPtr.Zero, IntPtr.Zero);
                if (pts != null && pts.Count > 1)
                {
                    Polyline pL5 = new Polyline() { Closed = false, Layer = "粗线" };
                    pL5.AddVertexAt(0, pts[0].Convert2D(), 0, 0, 0);
                    pL5.AddVertexAt(0, list[0].Convert2D(radius * 2 * scale, interval * scale * 2), 0, 0, 0);
                    ext = ext.Add(new Extents2d(pL5.Bounds.Value.MinPoint.Convert2D(), pL5.Bounds.Value.MaxPoint.Convert2D()));
                    //res.Add(pL5);
                }

                pts.Clear();
                pL4.IntersectWith((Entity)arc2, Intersect.ExtendBoth, pts, IntPtr.Zero, IntPtr.Zero);
                if (pts != null && pts.Count > 1)
                {
                    Polyline pL5 = new Polyline() { Closed = false, Layer = "粗线" };
                    pL5.AddVertexAt(0, list[0].Convert2D(radius * 2 * scale, interval * scale * 2), 0, 0, 0);
                    pL5.AddVertexAt(0, pts[0].Convert2D(), 0, 0, 0);
                    ext = ext.Add(new Extents2d(pL5.Bounds.Value.MinPoint.Convert2D(), pL5.Bounds.Value.MaxPoint.Convert2D()));
                    res.Add(pL5);
                }
                #endregion

                #region 垂直线

                // 底部斜口
                Polyline pBottom1 = new Polyline() { Closed = false, Layer = "粗线" };
                pBottom1.AddVertexAt(0, list[list.Count - 9].Convert2D(), 0, 0, 0);
                pBottom1.AddVertexAt(0, list[list.Count - 3].Convert2D(), 0, 0, 0);
                ext = ext.Add(new Extents2d(pBottom1.Bounds.Value.MinPoint.Convert2D(), pBottom1.Bounds.Value.MaxPoint.Convert2D()));
                res.Add(pBottom1);

                Polyline pBottom2 = new Polyline() { Closed = false, Layer = "粗线" };
                pBottom2.AddVertexAt(0, list[list.Count - 9].Convert2D(radius * 2 * scale), 0, 0, 0);
                pBottom2.AddVertexAt(0, list[list.Count - 2].Convert2D(), 0, 0, 0);
                ext = ext.Add(new Extents2d(pBottom2.Bounds.Value.MinPoint.Convert2D(), pBottom2.Bounds.Value.MaxPoint.Convert2D()));
                res.Add(pBottom2);


                // 计算每根钢筋的投影坐标
                double arcH = 0;
                double arcW = 0;

                List<Point3d> listArcPt = new List<Point3d>();
                listArcPt.Add(pt.Convert3D());
                for (int i = 1; i < rebarNum; ++i)
                {
                    // 计算圆点
                    double angle = 360 / rebarNum * i;

                    if (angle > 0 && angle < 90)
                    {
                        angle = GeTools.DegreeToRadian(angle);
                        arcH = Math.Abs(radius * Math.Sin(angle));
                        arcW = -Math.Abs(radius * Math.Cos(angle));
                    }
                    else if (angle > 90 && angle < 180)
                    {
                        angle = GeTools.DegreeToRadian(180 - angle);
                        arcH = Math.Abs(radius * Math.Sin(angle));
                        arcW = Math.Abs(radius * Math.Cos(angle));
                    }
                    else if (angle > 180 && angle < 270)
                    {
                        angle = GeTools.DegreeToRadian(270 - angle);
                        arcH = -Math.Abs(radius * Math.Cos(angle));
                        arcW = Math.Abs(radius * Math.Sin(angle));
                    }
                    else if (angle > 270 && angle < 360)
                    {
                        angle = GeTools.DegreeToRadian(360 - angle);
                        arcH = -Math.Abs(radius * Math.Sin(angle));
                        arcW = -Math.Abs(radius * Math.Cos(angle));
                    }
                    else if (angle == 0 || angle == 360)
                    {
                        arcH = -radius * Math.Sin(0);
                        arcW = -radius * Math.Cos(0);
                    }
                    else if (angle == 90)
                    {
                        arcH = radius * Math.Cos(0);
                        arcW = radius * Math.Sin(0);
                    }
                    else if (angle == 180)
                    {
                        angle = 360 - angle;
                        arcH = radius * Math.Sin(0);
                        arcW = radius * Math.Cos(0);
                    }
                    else if (angle == 270)
                    {
                        angle = 360 - angle;
                        arcH = -radius * Math.Cos(0);
                        arcW = radius * Math.Sin(0);
                    }

                    Point3d center = pt.Convert3D((radius + arcW)*scale);
                    listArcPt.Add(center);
                }

                listArcPt.Sort((a, b) => a.X.CompareTo(b.X));

                double arcRadius = radius;
                List<Point3d> listBak = new List<Point3d>();
                for (int i = 0; i < listArcPt.Count; ++i)
                {
                    double cosValue = 0;
                    double angle = 0;
                    double sinValue = 0;
                    Polyline line = new Polyline() { Closed = false, Layer = "粗线" };
                    // 计算垂直钢筋线与弧线的交点
                    if (listArcPt[i].X >= pt.X && listArcPt[i].X <= pt.X + spiralRadius * scale*2)
                    {
                        if (listArcPt[i].X >= arc3.Center.X - radius / 2 * scale && listArcPt[i].X <= arc3.Center.X + radius / 2 * scale)   // 左半边
                        { 
                            Polyline pl = new Polyline() { Closed = false, Layer = "粗线" };
                            pl.AddVertexAt(0, listArcPt[i].Convert2D(), 0, 0, 0);
                            pl.AddVertexAt(0, listArcPt[i].Convert2D(0, -height * scale), 0, 0, 0);

                            pts.Clear();
                            pl.IntersectWith((Entity)arc3, Intersect.ExtendBoth, pts, IntPtr.Zero, IntPtr.Zero);

                            if (listArcPt[i].X >= list[list.Count - 9].X && listArcPt[i].X <= list[list.Count - 3].X)
                            {
                                // 底部斜角
                                double w = Math.Abs(listArcPt[i].X - list[list.Count - 9].X);
                                Polyline p2 = new Polyline() { Closed = false, Layer = "粗线", LinetypeScale = 3, LineWeight = LineWeight.LineWeight015 };
                                p2.AddVertexAt(0, pts[0].Convert2D().Convert2D(), 0, 0, 0);
                                p2.AddVertexAt(0, list[list.Count - 9].Convert2D(w), 0, 0, 0);
                                ext = ext.Add(new Extents2d(p2.Bounds.Value.MinPoint.Convert2D(), p2.Bounds.Value.MaxPoint.Convert2D()));
                                res.Add(p2);

                                Polyline p3 = new Polyline() { Closed = false, Layer = "粗线", LinetypeScale = 3, LineWeight = LineWeight.LineWeight015 };
                                p3.AddVertexAt(0, list[list.Count - 9].Convert2D(w), 0, 0, 0);
                                p3.AddVertexAt(0, list[list.Count - 3].Convert2D(), 0, 0, 0);
                                ext = ext.Add(new Extents2d(p3.Bounds.Value.MinPoint.Convert2D(), p3.Bounds.Value.MaxPoint.Convert2D()));
                                res.Add(p3);
                            }
                            else
                            {
                                Polyline pLine = new Polyline() { Closed = false, Layer = "粗线" };
                                if (listArcPt[i].X <= arc3.Center.X)
                                {
                                    pLine.AddVertexAt(0, pts[0].Convert2D(), 0, 0, 0);
                                }
                                else if (listArcPt[i].X >= arc3.Center.X && listArcPt[i].X <= arc3.Center.X + radius / 2 * scale)
                                {
                                    pLine.AddVertexAt(0, pts[1].Convert2D(), 0, 0, 0);
                                }
                                //pLine.AddVertexAt(0, pts[0].Convert2D(), 0, 0, 0);
                                pLine.AddVertexAt(0, listArcPt[i].Convert2D(0, -(height - arcHeight) * scale), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pLine.Bounds.Value.MinPoint.Convert2D(), pLine.Bounds.Value.MaxPoint.Convert2D()));
                                res.Add(pLine);
                            }
                        }
                        else if (listArcPt[i].X >= arc2.Center.X - radius / 2 * scale && listArcPt[i].X <= arc2.Center.X + radius / 2 * scale)       // 右半边
                        {
                            Polyline pl = new Polyline() { Closed = false, Layer = "粗线" };
                            pl.AddVertexAt(0, listArcPt[i].Convert2D(), 0, 0, 0);
                            pl.AddVertexAt(0, listArcPt[i].Convert2D(0, -height * scale), 0, 0, 0);

                            pts.Clear();
                            pl.IntersectWith((Entity)arc2, Intersect.ExtendBoth, pts, IntPtr.Zero, IntPtr.Zero);

                            if (listArcPt[i].X >= list[list.Count - 2].X && listArcPt[i].X <= (list[list.Count - 9].X + radius * 2 * scale))
                            {
                                // 下部斜角
                                double w = Math.Abs(listArcPt[i].X - list[list.Count - 9].X);
                                Polyline p2 = new Polyline() { Closed = false, Layer = "粗线", LinetypeScale = 3, LineWeight = LineWeight.LineWeight015 };
                                p2.AddVertexAt(0, pts[0].Convert2D(), 0, 0, 0);
                                p2.AddVertexAt(0, list[list.Count - 9].Convert2D(w), 0, 0, 0);
                                ext = ext.Add(new Extents2d(p2.Bounds.Value.MinPoint.Convert2D(), p2.Bounds.Value.MaxPoint.Convert2D()));
                                res.Add(p2);

                                Polyline p3 = new Polyline() { Closed = false, Layer = "粗线", LinetypeScale = 3, LineWeight = LineWeight.LineWeight015 };
                                p3.AddVertexAt(0, list[list.Count - 9].Convert2D(w), 0, 0, 0);
                                p3.AddVertexAt(0, list[list.Count - 2].Convert2D(), 0, 0, 0);
                                ext = ext.Add(new Extents2d(p3.Bounds.Value.MinPoint.Convert2D(), p3.Bounds.Value.MaxPoint.Convert2D()));
                                res.Add(p3);
                            }
                            else
                            {
                                Polyline pLine = new Polyline() { Closed = false, Layer = "粗线" };
                                if (listArcPt[i].X >= arc2.Center.X - radius / 2 * scale && listArcPt[i].X <= arc2.Center.X)
                                {
                                    pLine.AddVertexAt(0, pts[1].Convert2D(), 0, 0, 0);
                                }
                                else if (listArcPt[i].X >= arc2.Center.X && listArcPt[i].X <= arc2.Center.X + radius / 2 * scale)
                                {
                                    pLine.AddVertexAt(0, pts[0].Convert2D(), 0, 0, 0);
                                }

                                pLine.AddVertexAt(0, listArcPt[i].Convert2D(0, -(height - arcHeight) * scale), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pLine.Bounds.Value.MinPoint.Convert2D(), pLine.Bounds.Value.MaxPoint.Convert2D()));
                                res.Add(pLine);
                            }
                        }
                        else
                        {
                            Polyline pl = new Polyline() { Closed = false, Layer = "粗线" };
                            pl.AddVertexAt(0, listArcPt[i].Convert2D(0, arcHeight*scale), 0, 0, 0);
                            pl.AddVertexAt(0, listArcPt[i].Convert2D(0, -(height- arcHeight) * scale), 0, 0, 0);
                            ext = ext.Add(new Extents2d(pl.Bounds.Value.MinPoint.Convert2D(), pl.Bounds.Value.MaxPoint.Convert2D()));
                            res.Add(pl);
                        }
                    }
                }

                #endregion

                #region 固定件
                // 左边
                double w1 = radius*0.2;

                Point2d fixedPt1 = list[0].Convert2D(0,-height/3*scale);
                Polyline plFixedPart1 = new Polyline() { Closed = false, Layer = "粗线", LinetypeScale = 3, LineWeight = LineWeight.LineWeight100 };
                plFixedPart1.AddVertexAt(0, fixedPt1.Convert2D(0,15*scale),0,0,0);
                plFixedPart1.AddVertexAt(0, fixedPt1.Convert2D(0, 10 * scale), 0, 0, 0);
                plFixedPart1.AddVertexAt(0, fixedPt1.Convert2D(-w1, 5 * scale), 0, 0, 0);
                plFixedPart1.AddVertexAt(0, fixedPt1.Convert2D(-w1, -5 * scale), 0, 0, 0);
                plFixedPart1.AddVertexAt(0, fixedPt1.Convert2D(0, -10 * scale), 0, 0, 0);
                plFixedPart1.AddVertexAt(0, fixedPt1.Convert2D(0, 15 * scale), 0, 0, 0);
                ext = ext.Add(new Extents2d(plFixedPart1.Bounds.Value.MinPoint.Convert2D(), plFixedPart1.Bounds.Value.MaxPoint.Convert2D()));
                res.Add(plFixedPart1);

                Point2d fixedPt2 = list[0].Convert2D(0, -height*2 / 3 * scale);
                Polyline plFixedPart2 = new Polyline() { Closed = false, Layer = "粗线", LinetypeScale = 3, LineWeight = LineWeight.LineWeight100 };
                plFixedPart2.AddVertexAt(0, fixedPt2.Convert2D(0, 15 * scale), 0, 0, 0);
                plFixedPart2.AddVertexAt(0, fixedPt2.Convert2D(0, 10 * scale), 0, 0, 0);
                plFixedPart2.AddVertexAt(0, fixedPt2.Convert2D(-w1, 5 * scale), 0, 0, 0);
                plFixedPart2.AddVertexAt(0, fixedPt2.Convert2D(-w1, -5 * scale), 0, 0, 0);
                plFixedPart2.AddVertexAt(0, fixedPt2.Convert2D(0, -10 * scale), 0, 0, 0);
                plFixedPart2.AddVertexAt(0, fixedPt2.Convert2D(0, 15 * scale), 0, 0, 0);
                ext = ext.Add(new Extents2d(plFixedPart2.Bounds.Value.MinPoint.Convert2D(), plFixedPart2.Bounds.Value.MaxPoint.Convert2D()));
                res.Add(plFixedPart2);

                // 右边
                Point2d fixedPt3 = list[1].Convert2D(0, -height / 3 * scale);
                Polyline plFixedPart3= new Polyline() { Closed = false, Layer = "粗线", LinetypeScale = 3, LineWeight = LineWeight.LineWeight100 };
                plFixedPart3.AddVertexAt(0, fixedPt3.Convert2D(0, 15 * scale), 0, 0, 0);
                plFixedPart3.AddVertexAt(0, fixedPt3.Convert2D(0, 10 * scale), 0, 0, 0);
                plFixedPart3.AddVertexAt(0, fixedPt3.Convert2D(w1, 5 * scale), 0, 0, 0);
                plFixedPart3.AddVertexAt(0, fixedPt3.Convert2D(w1, -5 * scale), 0, 0, 0);
                plFixedPart3.AddVertexAt(0, fixedPt3.Convert2D(0, -10 * scale), 0, 0, 0);
                plFixedPart3.AddVertexAt(0, fixedPt3.Convert2D(0, 15 * scale), 0, 0, 0);
                ext = ext.Add(new Extents2d(plFixedPart3.Bounds.Value.MinPoint.Convert2D(), plFixedPart3.Bounds.Value.MaxPoint.Convert2D()));
                res.Add(plFixedPart3);

                Point2d fixedPt4 = list[1].Convert2D(0, -height *2/ 3 * scale);
                Polyline plFixedPart4 = new Polyline() { Closed = false, Layer = "粗线", LinetypeScale = 3, LineWeight = LineWeight.LineWeight100 };
                plFixedPart4.AddVertexAt(0, fixedPt4.Convert2D(0, 15 * scale), 0, 0, 0);
                plFixedPart4.AddVertexAt(0, fixedPt4.Convert2D(0, 10 * scale), 0, 0, 0);
                plFixedPart4.AddVertexAt(0, fixedPt4.Convert2D(w1, 5 * scale), 0, 0, 0);
                plFixedPart4.AddVertexAt(0, fixedPt4.Convert2D(w1, -5 * scale), 0, 0, 0);
                plFixedPart4.AddVertexAt(0, fixedPt4.Convert2D(0, -10 * scale), 0, 0, 0);
                plFixedPart4.AddVertexAt(0, fixedPt4.Convert2D(0, 15 * scale), 0, 0, 0);
                ext = ext.Add(new Extents2d(plFixedPart4.Bounds.Value.MinPoint.Convert2D(), plFixedPart4.Bounds.Value.MaxPoint.Convert2D()));
                res.Add(plFixedPart4);

                #endregion

                foreach (DBObject drawitem in res)
                {
                    recorder.AppendEntity((Entity)drawitem);
                    tr.AddNewlyCreatedDBObject(drawitem, true);
                }

                tr.Commit();
            }
        }

        public static Point2d GetCrossPoint(Polyline PL,Arc arc)
        {
            Point2d pt = new Point2d();
            //Curve curEnt1 = PL as Curve;
            //Curve curEnt2 = arc as Curve;
            //PL.
            ////获取切线方向的垂线向量 （从切线得到法线）
            //Vector3d curPervector = curVector.GetPerpendicularVector();
            return pt;
        }

        /// <summary>
        /// 绘制承台平面图
        /// </summary>
        /// <param name="db"></param>
        /// <param name="ext"></param>
        /// <param name="startPt">绘制起点</param>
        /// <param name="arrayBarTop">外侧上下配筋</param>
        /// <param name="arrayBarLeft">外侧左右配筋</param>
        /// <param name="mainReinforcement">主筋横、纵向间距</param>
        /// <param name="pillarCenter">台柱中心点</param>
        /// <param name="pillarRadius">台柱半径</param>
        /// <param name="pillarWidth">承台宽度</param>
        /// <param name="pillarLength">承台长度</param>
        /// <param name="radius">配筋截面半径</param>
        /// <param name="CoverThk">厚度</param>
        /// <param name="scale">比例</param>
        public static void CreatePlotElevationEF(Database db, ref Extents2d ext, Point2d startPt, 
            List<double> arrayBarTop, List<double> arrayBarLeft, List<double> ArrAlongWE, List<double> ArrAlongLE, List<Point3d> pillarCenter,double pillarRadius,
            double pillarWidth, double pillarLength, double radius, double CoverThk, int scale,Dictionary<int, int> dicNo, double N5Dia)
        {
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                DBObjectCollection res = new DBObjectCollection();
                #region 承台边框
                Polyline pl1 = new Polyline() { Closed = true, Layer = "细线" };
                Point2d pt1 = startPt;
                Point2d pt2 = pt1.Convert2D(0,-pillarLength);
                Point2d pt3 = pt2.Convert2D(pillarWidth);
                Point2d pt4 = pt3.Convert2D(0, pillarLength);

                pl1.AddVertexAt(0, pt1,0,0,0);
                pl1.AddVertexAt(1, pt2, 0, 0, 0);
                pl1.AddVertexAt(2, pt3, 0, 0, 0);
                pl1.AddVertexAt(3, pt4, 0, 0, 0);

                //ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.Convert2D(), pl1.Bounds.Value.MaxPoint.Convert2D()));
                //res.Add(pl1);
                #endregion

                double reinforcementLength = 0;       // 纵向配筋长度
                double reinforcementwidth = 0;         // 横向配筋长度

                List<Point3d> vList = new List<Point3d>();      // 右边最外侧垂直圆心
                List<Point3d> hList = new List<Point3d>();      // 底部最下边横向圆心

                double offsetX = 0;
                for (int i = 0; i < arrayBarTop.Count; ++i)
                {
                    offsetX += arrayBarTop[i];
                }
                reinforcementLength = offsetX;

                double offsetY = 0;
                for (int i = 0; i < arrayBarLeft.Count; ++i)
                {
                    offsetY += arrayBarLeft[i];
                }
                reinforcementwidth = offsetY;
                #region 实心圆
                // 纵向
                Point3d pt = startPt.Convert3D(CoverThk+ N5Dia * 0.5, -CoverThk-radius * scale);
                CreateSolidCircle(db,ref ext, pt, radius*scale);
                double marginX = 0;
                for (int i = 0; i < arrayBarTop.Count; ++i)
                {
                    if (i == 0 || i == arrayBarTop.Count - 1)
                    {
                        marginX += N5Dia * 0.5;
                    }
                    marginX += arrayBarTop[i];
                    pt = startPt.Convert3D(CoverThk+ N5Dia  + marginX, -CoverThk-radius * scale);
                    CreateSolidCircle(db, ref ext, pt, radius* scale);

                    CreateSolidCircle(db, ref ext, pt.Convert3D(0, -reinforcementwidth - radius * 2 * scale), radius * scale);
                    vList.Add(pt.Convert3D(0, -reinforcementwidth - radius * 2 * scale));
                }


                // 横向
                double marginY = 0;
                for (int i = 0; i < arrayBarLeft.Count; ++i)
                {
                    if(i == 0 || i == arrayBarLeft.Count-1)
                    {
                        marginY += N5Dia * 0.5;
                    }
                    marginY += arrayBarLeft[i];
                    
                    pt = startPt.Convert3D(CoverThk+radius * scale, -CoverThk - marginY- N5Dia * 0.5);

                    CreateSolidCircle(db, ref ext, pt, radius * scale);
                    CreateSolidCircle(db, ref ext, pt.Convert3D(reinforcementLength + radius * 2 * scale), radius * scale);
                    hList.Add(pt.Convert3D(reinforcementLength + radius * 2 * scale));
                }

                #endregion

                #region 台柱
                pt = startPt.Convert3D(pillarWidth / 4, -pillarLength / 4);
                Circle firstCircle = new Circle(pt.Convert3D(), Vector3d.ZAxis, pillarRadius);
                for (int i = 0; i < 2; ++i)
                {
                    for (int j = 0; j < 2; ++j)
                    {
                        pt = startPt.Convert3D(pillarWidth / 4 + pillarWidth / 2 * j, -pillarLength / 4 - pillarLength / 2 * i);
                        Circle a = new Circle(pt.Convert3D(), Vector3d.ZAxis, pillarRadius) { Layer = "粗线" };
                        ext = ext.Add(new Extents2d(a.Bounds.Value.MinPoint.Convert2D(), a.Bounds.Value.MaxPoint.Convert2D()));
                        res.Add(a);
                    }
                }
                #endregion

                #region 外侧配筋
                // 纵向配筋
                Point3dCollection pts = new Point3dCollection();
                pt = startPt.Convert3D(CoverThk + radius*scale, -CoverThk - radius * scale);
                Polyline pl2 = new Polyline() { Closed = false, Layer = "粗线", ColorIndex=1 };
                Point2d p1 = pt.Convert2D(radius * scale, -radius * scale);
                Point2d p2 = p1.Convert2D(0, -reinforcementwidth);

                pl2.AddVertexAt(0, p1, 0, 0, 0);
                pl2.AddVertexAt(0, p2, 0, 0, 0);

                ext = ext.Add(new Extents2d(pl2.Bounds.Value.MinPoint.Convert2D(), pl2.Bounds.Value.MaxPoint.Convert2D()));
                res.Add(pl2);

                marginX = 0;
                for (int i = 0; i < arrayBarTop.Count; ++i)
                {
                    if (i == 0 || i == arrayBarTop.Count - 1)
                    {
                        marginX += radius * scale;
                    }
                    marginX += arrayBarTop[i];
                    pt = startPt.Convert3D(CoverThk +radius * scale + marginX, -CoverThk-radius * scale);
                    Polyline pl3 = new Polyline() { Closed = false, Layer = "粗线", ColorIndex = 1 };

                    if(i == arrayBarTop.Count-1)
                    {
                        p1 = pt.Convert2D(-radius * scale, -radius * scale);
                        p2 = p1.Convert2D(0, -reinforcementwidth);
                    }
                    else
                    {
                        p1 = pt.Convert2D(0, -radius * scale);
                        p2 = p1.Convert2D(0, -reinforcementwidth);
                    }

                    pl3.AddVertexAt(0, p1,0,0,0);
                    pl3.AddVertexAt(0, p2, 0, 0, 0);

                    // 计算与圆柱的交点
                    //pts.Clear();
                    //pl3.IntersectWith((Entity)firstCircle, Intersect.ExtendBoth, pts, IntPtr.Zero, IntPtr.Zero);
                    //if(pts != null)
                    //{
                    //    if (pts.Count == 1 || pts.Count == 0)
                    //    {
                    //        ext = ext.Add(new Extents2d(pl3.Bounds.Value.MinPoint.Convert2D(), pl3.Bounds.Value.MaxPoint.Convert2D()));
                    //        res.Add(pl3);
                    //    }
                    //    else if (pts.Count == 2)
                    //    {
                    //        Polyline pl = new Polyline() { Closed = false, Layer = "粗线" };
                    //        if(p1.X>= firstCircle.Center.X - pillarRadius && p1.X <= firstCircle.Center.X)
                    //        {
                    //            pl.AddVertexAt(0, p1, 0, 0, 0);
                    //            pl.AddVertexAt(0, pts[1].Convert2D(), 0, 0, 0);
                    //            ext = ext.Add(new Extents2d(pl.Bounds.Value.MinPoint.Convert2D(), pl.Bounds.Value.MaxPoint.Convert2D()));
                    //            res.Add(pl);

                    //            pl = new Polyline() { Closed = false, Layer = "粗线" };
                    //            pl.AddVertexAt(0, pts[0].Convert2D(), 0, 0, 0);
                    //            pl.AddVertexAt(0, p2, 0, 0, 0);
                    //        }
                    //        else if(p1.X >= firstCircle.Center.X && p1.X <= firstCircle.Center.X + pillarRadius)
                    //        {
                    //            pl.AddVertexAt(0, p1, 0, 0, 0);
                    //            pl.AddVertexAt(0, pts[0].Convert2D(), 0, 0, 0);
                    //            ext = ext.Add(new Extents2d(pl.Bounds.Value.MinPoint.Convert2D(), pl.Bounds.Value.MaxPoint.Convert2D()));
                    //            res.Add(pl);

                    //            pl = new Polyline() { Closed = false, Layer = "粗线" };
                    //            pl.AddVertexAt(0, pts[1].Convert2D(), 0, 0, 0);
                    //            pl.AddVertexAt(0, p2, 0, 0, 0);
                    //        }
                    //        ext = ext.Add(new Extents2d(pl.Bounds.Value.MinPoint.Convert2D(), pl.Bounds.Value.MaxPoint.Convert2D()));
                    //        res.Add(pl);
                    //    }
                    //}
                    ext = ext.Add(new Extents2d(pl3.Bounds.Value.MinPoint.Convert2D(), pl3.Bounds.Value.MaxPoint.Convert2D()));
                    res.Add(pl3);
                }

                // 横向配筋
                pt = startPt.Convert3D(CoverThk+radius * scale, -CoverThk-radius * scale);
                pl2 = new Polyline() { Closed = false, Layer = "粗线", ColorIndex = 1, };
                p1 = pt.Convert2D(radius * scale, -radius * scale);
                p2 = p1.Convert2D(reinforcementLength);

                pl2.AddVertexAt(0, p1, 0, 0, 0);
                pl2.AddVertexAt(0, p2, 0, 0, 0);

                ext = ext.Add(new Extents2d(pl2.Bounds.Value.MinPoint.Convert2D(), pl2.Bounds.Value.MaxPoint.Convert2D()));
                res.Add(pl2);

                marginY = 0;
                for (int i = 0; i < arrayBarLeft.Count;++i)
                {
                    if (i == 0 || i == arrayBarLeft.Count - 1)
                    {
                        marginY += radius * scale;
                    }
                    marginY += arrayBarLeft[i];
                    pt = startPt.Convert3D(CoverThk+radius * scale, -CoverThk - marginY-radius * scale);
                    Polyline pl4 = new Polyline() { Closed = false, Layer = "粗线", ColorIndex = 1 };
                    
                    
                    if (i == arrayBarLeft.Count - 1)
                    {
                        p1 = pt.Convert2D(radius * scale, radius * scale);
                        p2 = p1.Convert2D(reinforcementLength);
                    }
                    else
                    {
                        p1 = pt.Convert2D(radius * scale);
                        p2 = p1.Convert2D(reinforcementLength);
                    }
                    pl4.AddVertexAt(0, p1, 0, 0, 0);
                    pl4.AddVertexAt(0, p2, 0, 0, 0);

                    // 计算与圆柱的交点
                    //pts.Clear();
                    //pl4.IntersectWith((Entity)firstCircle, Intersect.ExtendBoth, pts, IntPtr.Zero, IntPtr.Zero);
                    //if (pts != null)
                    //{
                    //    if (pts.Count == 1 || pts.Count == 0)
                    //    {
                    //        ext = ext.Add(new Extents2d(pl4.Bounds.Value.MinPoint.Convert2D(), pl4.Bounds.Value.MaxPoint.Convert2D()));
                    //        res.Add(pl4);
                    //    }
                    //    else if (pts.Count == 2)
                    //    {
                    //        Polyline pl = new Polyline() { Closed = false, Layer = "粗线" };
                    //        if (p1.Y <= firstCircle.Center.Y+pillarRadius && p1.Y >= firstCircle.Center.Y)
                    //        {
                    //            pl.AddVertexAt(0, p1, 0, 0, 0);
                    //            pl.AddVertexAt(0, pts[0].Convert2D(), 0, 0, 0);
                    //            ext = ext.Add(new Extents2d(pl.Bounds.Value.MinPoint.Convert2D(), pl.Bounds.Value.MaxPoint.Convert2D()));
                    //            res.Add(pl);

                    //            pl = new Polyline() { Closed = false, Layer = "粗线" };
                    //            pl.AddVertexAt(0, pts[1].Convert2D(), 0, 0, 0);
                    //            pl.AddVertexAt(0, p2, 0, 0, 0);
                    //        }
                    //        if (p1.Y <= firstCircle.Center.Y  && p1.Y >= firstCircle.Center.Y - pillarRadius)
                    //        {

                    //            pl.AddVertexAt(0, p1, 0, 0, 0);
                    //            pl.AddVertexAt(0, pts[1].Convert2D(), 0, 0, 0);
                    //            ext = ext.Add(new Extents2d(pl.Bounds.Value.MinPoint.Convert2D(), pl.Bounds.Value.MaxPoint.Convert2D()));
                    //            res.Add(pl);

                    //            pl = new Polyline() { Closed = false, Layer = "粗线" };
                    //            pl.AddVertexAt(0, pts[0].Convert2D(), 0, 0, 0);
                    //            pl.AddVertexAt(0, p2, 0, 0, 0);
                    //        }
                    //        ext = ext.Add(new Extents2d(pl.Bounds.Value.MinPoint.Convert2D(), pl.Bounds.Value.MaxPoint.Convert2D()));
                    //        res.Add(pl);
                    //    }
                    //}

                    ext = ext.Add(new Extents2d(pl4.Bounds.Value.MinPoint.Convert2D(), pl4.Bounds.Value.MaxPoint.Convert2D()));
                    res.Add(pl4);
                }
                #endregion

                #region 主筋
                // 计算主筋数量
                offsetX = 0;
                offsetY = 0;
                List<List<Point3d>> ps = new List<List<Point3d>>();
                if (ArrAlongWE != null && ArrAlongLE != null)
                {
                    for(int i = 0; i < ArrAlongWE.Count;++i)        // 行间隔
                    {
                        List<Point3d> list1 = new List<Point3d>();
                        offsetY += ArrAlongWE[i];
                        offsetX = 0;
                        for (int j = 0; j < ArrAlongLE.Count; ++j)  // 列间隔
                        {
                            offsetX += ArrAlongLE[j];
                            pt = startPt.Convert3D(CoverThk+ radius*3*scale+ offsetX, -CoverThk- offsetY-radius*scale);
                            CreateSolidCircle(db, ref ext, pt, radius*scale);
                            list1.Add(pt);
                        }
                        ps.Add(list1);
                    }
                }
                #endregion

                #region 标注和其他
                RotatedDimension dim0 = DimPloter.AddRotDim(db, ref ext, startPt.Convert3D(), startPt.Convert3D(0,-CoverThk- N5Dia * 0.5), startPt.Convert3D(-5*scale),
                    scale, 90,"cm");
                res.Add(dim0);

                RotatedDimension dim1 = DimPloter.AddRotDim(db, ref ext, startPt.Convert3D(0, -CoverThk - N5Dia * 0.5), startPt.Convert3D(0, -pillarLength + CoverThk + N5Dia * 0.5), startPt.Convert3D(-5 * scale),
                    scale, 90, "cm");
                res.Add(dim1);

                RotatedDimension dim2 = DimPloter.AddRotDim(db, ref ext, startPt.Convert3D(0, -pillarLength + CoverThk + N5Dia * 0.5), startPt.Convert3D(0, -pillarLength), startPt.Convert3D(-5 * scale, -pillarLength),
                    scale, 90,"cm");
                res.Add(dim2);

                RotatedDimension dim3 = DimPloter.AddRotDim(db, ref ext, startPt.Convert3D(), startPt.Convert3D(0, -pillarLength), startPt.Convert3D(-10 * scale),
                    scale, 90, "cm");
                res.Add(dim3);


                RotatedDimension dim4 = DimPloter.AddRotDim(db, ref ext, startPt.Convert3D(), startPt.Convert3D(CoverThk + N5Dia * 0.5), startPt.Convert3D(0, 7 * scale),
                    scale, 0, "cm");
                res.Add(dim4);

                RotatedDimension dim5 = DimPloter.AddRotDim(db, ref ext, startPt.Convert3D(CoverThk + N5Dia * 0.5), startPt.Convert3D(pillarWidth - CoverThk - N5Dia * 0.5), startPt.Convert3D(0, 7 * scale),
                    scale, 0, "cm");
                res.Add(dim5);

                RotatedDimension dim6 = DimPloter.AddRotDim(db, ref ext, startPt.Convert3D(pillarWidth - CoverThk - N5Dia * 0.5), startPt.Convert3D(pillarWidth), startPt.Convert3D(0, 7 * scale),
                    scale, 0, "cm");
                res.Add(dim6);

                RotatedDimension dim7 = DimPloter.AddRotDim(db, ref ext, startPt.Convert3D(), startPt.Convert3D(pillarWidth), startPt.Convert3D(0,12 * scale),
                    scale, 0, "cm");
                res.Add(dim7);
                #endregion

                #region 标记
                List<Point3d> list = new List<Point3d>();
                // 右侧标记
                int hIndex = 0;         // 标记外筋个数
                if(hList.Count <=4)
                {
                    hIndex = 1;
                }
                else if(hList.Count > 4 && hList.Count <= 10)
                {
                    hIndex = 2;
                }
                else
                {
                    hIndex = 5;
                }
                if(hList != null && hList.Count >0 )
                {
                    for (int i = 0; i < hIndex && i < hList.Count - 1; ++i)
                    {
                        Point3d flg1 = hList[i];
                        list.Add(flg1.Convert3D(radius * scale));
                    }

                    for (int i = hList.Count - hIndex - 1; i < hList.Count; ++i)
                    {
                        Point3d flg1 = hList[i];
                        list.Add(flg1.Convert3D(radius * scale));
                    }

                    PolylinePloter.CreateRebarPointLine(db, ref ext, eDirection.E_RIGHT, list, dicNo[5].ToString(), list.Count / 2, list.Count / 2, scale);
                }

                // 底部标记
                list.Clear();
                int vIndex = 0;         // 标记外筋个数
                if (vList.Count <= 4)
                {
                    vIndex = 1;
                }
                else if (vList.Count > 4 && vList.Count <= 10)
                {
                    vIndex = 2;
                }
                else
                {
                    vIndex = 5;
                }
                if(vList != null && vList.Count > 0)
                {
                    for (int i = 0; i < vIndex && i < vList.Count - 1; ++i)
                    {
                        Point3d flg1 = vList[i];
                        list.Add(flg1.Convert3D(0, -radius * scale));
                    }

                    for (int i = vList.Count - vIndex - 1; i < vList.Count; ++i)
                    {
                        Point3d flg1 = vList[i];
                        list.Add(flg1.Convert3D(0, -radius * scale));
                    }

                    PolylinePloter.CreateRebarPointLine(db, ref ext, eDirection.E_TOP, list, dicNo[5].ToString(), list.Count / 2, list.Count / 2, scale);
                }

                // 主筋标记
                if (ps != null && ps.Count > 0)
                {
                    List<Point3d> l1 = new List<Point3d>();
                    Point2d pt7 = Point2d.Origin;
                    int startIndex = 0;
                    int lastIndex = 0;
                    if (ps.Count <= 3)
                    {
                        startIndex = 0;
                        lastIndex = ps.Count;
                    }
                    else
                    {
                        //startIndex = (ps.Count - 3) / 2;
                        startIndex = 0;
                        lastIndex = startIndex + 3;
                    }
                    //pt7 = ps[startIndex][ps[startIndex].Count - 1].Convert2D(20 * scale, 3 * scale);
                    double marginMarkCenter = 0;
                    if (ArrAlongWE != null && ArrAlongWE.Count > 0)
                    {
                        marginMarkCenter = ArrAlongWE[0];
                    }
                    pt7 = ps[startIndex][ps[startIndex].Count - 1].Convert2D(-3*scale, CoverThk + radius*scale*2+marginMarkCenter);

                    int markCol = 2;            // 标记主筋列数
                    for (int i = startIndex; i < lastIndex && i < ps.Count; ++i)
                    {
                        int count = ps[i].Count;
                        markCol = count == 1 ? 1 : 2;
                        for (int j = count - markCol; j < count; ++j)
                        {
                            Polyline pll1 = new Polyline() { Closed = false, Layer = "粗线" };
                            Point2d pt5 = ps[i][j].Convert2D();

                            pll1.AddVertexAt(0, pt5, 0, 0, 0);
                            pll1.AddVertexAt(0, pt7, 0, 0, 0);

                            ext = ext.Add(new Extents2d(pll1.Bounds.Value.MinPoint.Convert2D(), pll1.Bounds.Value.MaxPoint.Convert2D()));
                            res.Add(pll1);
                        }
                    }

                    DimPloter.CircularMark(db, ref ext, pt7.Convert3D(-2.5*scale,2.5*scale), dicNo[8].ToString(), Extensions.curFont, scale);
                }
                #endregion

                foreach (DBObject drawitem in res)
                {
                    recorder.AppendEntity((Entity)drawitem);
                    tr.AddNewlyCreatedDBObject(drawitem, true);
                }
                
                tr.Commit();

                ext = ext.Add(new Extents2d(dim0.Bounds.Value.MinPoint.Convert2D(), dim0.Bounds.Value.MaxPoint.Convert2D()));
                ext = ext.Add(new Extents2d(dim1.Bounds.Value.MinPoint.Convert2D(), dim1.Bounds.Value.MaxPoint.Convert2D()));
                ext = ext.Add(new Extents2d(dim2.Bounds.Value.MinPoint.Convert2D(), dim2.Bounds.Value.MaxPoint.Convert2D()));
                ext = ext.Add(new Extents2d(dim3.Bounds.Value.MinPoint.Convert2D(), dim3.Bounds.Value.MaxPoint.Convert2D()));
                ext = ext.Add(new Extents2d(dim4.Bounds.Value.MinPoint.Convert2D(), dim4.Bounds.Value.MaxPoint.Convert2D()));
                ext = ext.Add(new Extents2d(dim5.Bounds.Value.MinPoint.Convert2D(), dim5.Bounds.Value.MaxPoint.Convert2D()));
                ext = ext.Add(new Extents2d(dim6.Bounds.Value.MinPoint.Convert2D(), dim6.Bounds.Value.MaxPoint.Convert2D()));
                ext = ext.Add(new Extents2d(dim7.Bounds.Value.MinPoint.Convert2D(), dim7.Bounds.Value.MaxPoint.Convert2D()));
            }
       }

        /// <summary>
        /// 三角撑
        /// </summary>
        /// <param name="db"></param>
        /// <param name="ext"></param>
        /// <param name="startPoint"></param>
        /// <param name="radius"></param>
        /// <param name="T1"></param>
        /// <param name="T2"></param>
        /// <param name="T3"></param>
        /// <param name="scale"></param>
        /// <param name="isDrawTriangleTie">是否绘制三角撑</param>
        /// <param name="isDrawFaceWeld">是否绘制焊接面</param>
        public static void CreatePileTriangleTie(Database db, ref Extents2d ext, Point3d startPoint,
            double radius, string T1, string T2, int T3, double scale, bool isDrawTriangleTie = true,
            bool isDrawFaceWeld = true, string replaceDim="")
        {
            DBObjectCollection res = new DBObjectCollection();
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                // 圆
                Circle exCircle = new Circle(startPoint.Add(new Vector3d(radius, 0, 0)), Vector3d.ZAxis, radius) { Layer = "粗线" };
                res.Add(exCircle);
                ext = ext.Add(new Extents2d(exCircle.Bounds.Value.MinPoint.Convert2D(), exCircle.Bounds.Value.MaxPoint.Convert2D()));

                // 三角撑
                int soundPipeNum = 3;

                Point3d p1, p2, p3, center;
                center = startPoint.Convert3D(radius);
                p1 = startPoint.Convert3D(radius, radius);
                p2 = center.Convert3D(-radius * Math.Cos(GeTools.DegreeToRadian(30)), -radius*Math.Sin(GeTools.DegreeToRadian(30)));
                p3 = center.Convert3D(radius * Math.Cos(GeTools.DegreeToRadian(30)), -radius * Math.Sin(GeTools.DegreeToRadian(30)));

                if(isDrawTriangleTie)
                {
                    Polyline pl1 = new Polyline() { Closed = true, Layer = "粗线" };
                    pl1.AddVertexAt(0, p1.Convert2D(), 0, 0, 0);
                    pl1.AddVertexAt(1, p2.Convert2D(), 0, 0, 0);
                    pl1.AddVertexAt(2, p3.Convert2D(), 0, 0, 0);
                    ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.Convert2D(), pl1.Bounds.Value.MaxPoint.Convert2D()));
                    res.Add(pl1);
                }
                #region 引线
                double width1 = 0;
                MText txt1 = TextPloter.GetTextActualWidth(db, T1, scale, 2.5, Extensions.curFont);
                width1 = txt1.ActualWidth;
                double width2 = 0;
                MText txt2 = TextPloter.GetTextActualWidth(db, T2, scale,2.5, Extensions.curFont);
                width2 = txt2.ActualWidth;
                double lineWidth = width1 > width2 ? width1 : width2;

                DimPloter.RebarWire(db, ref ext, center.Convert2D(radius * Math.Cos(GeTools.DegreeToRadian(45)), radius * Math.Sin(GeTools.DegreeToRadian(45))), T1,T2,T3,
                    GeTools.DegreeToRadian(0),Extensions.curFont,scale);

                // 直径标记
                DimPloter.CreateDiameterMark(db, ref ext, startPoint, eArrow.E_ARROW_DOUBLE_SIDE_ARROW, radius * 2, 
                    "D253.4", scale, -15);

                if (isDrawTriangleTie)
                {
                    // 支撑架标记
                    double offsetWidth = radius / 10;
                    Point3d p4 = center.Convert3D(radius/2*Math.Cos(GeTools.DegreeToRadian(30)),
                        radius / 2 * Math.Sin(GeTools.DegreeToRadian(30)));

                    // 圆形标记
                    DimPloter.CreateHookLineMark(db, ref ext, p4, "2", offsetWidth, scale);
                }
                // 焊接面
                if(isDrawFaceWeld)
                {
                    DimPloter.CreateFaceWeld(db, ref ext, startPoint.Add(new Vector3d(radius, 0, 0)), radius, scale, replaceDim);
                    DimPloter.CreateLeadWireWithoutCircleMark(db, ref ext, startPoint.Convert3D(radius, -radius),
                        "单面焊", "", Extensions.curFont, scale);
                }
                
                #endregion

                foreach (DBObject drawitem in res)
                {
                    recorder.AppendEntity((Entity)drawitem);
                    tr.AddNewlyCreatedDBObject(drawitem, true);
                }

                tr.Commit();
            }
        }

        public static void CreatePileReber(Database db, ref Extents2d ext, Point3d startPoint,
         double radius, string T1, string T2, int T3, double scale, bool isDrawTriangleTie = true,
         bool isDrawFaceWeld = true, string replaceDim = "")
        {
            DBObjectCollection res = new DBObjectCollection();
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                Polyline pl1 = new Polyline() { Closed = true, Layer = "粗线" };
                pl1.AddVertexAt(0, startPoint.Convert2D(), 0, 0, 0);
                pl1.AddVertexAt(1, startPoint.Convert2D(2 * radius), 0, 0, 0);
                ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.Convert2D(), pl1.Bounds.Value.MaxPoint.Convert2D()));
                res.Add(pl1);
                DBText txt = new DBText();
                txt.TextString = T2;
                txt.Height = 2.5 * scale;
                txt.Position = startPoint.Convert3D(radius, -2.5 * scale);
                txt.HorizontalMode = TextHorizontalMode.TextCenter;
                txt.VerticalMode = TextVerticalMode.TextVerticalMid;
                txt.AlignmentPoint = startPoint.Convert3D(radius, -2.5 * scale);
                txt.TextStyleId = st[Extensions.curFont];
                txt.Layer = "标注";
                txt.WidthFactor = 0.8;
                res.Add(txt);
                ext = ext.Add(new Extents2d(txt.Bounds.Value.MinPoint.Convert2D(), txt.Bounds.Value.MaxPoint.Convert2D()));

                #region 引线

                DimPloter.RebarWire(db, ref ext, startPoint.Convert2D(radius), T1, T2, T3,
                    GeTools.DegreeToRadian(0), Extensions.curFont, scale);


                #endregion

                foreach (DBObject drawitem in res)
                {
                    recorder.AppendEntity((Entity)drawitem);
                    tr.AddNewlyCreatedDBObject(drawitem, true);
                }

                tr.Commit();
            }
        }

        public static void AddCircle(Point2d pt, double radius, ref Extents2d ext, string layerName = "标注", double scale = 1)
        {
            //DBObjectCollection res = new DBObjectCollection();
            Database db = HostApplicationServices.WorkingDatabase;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                Circle circle = new Circle(pt.Convert3D(), Vector3d.ZAxis, radius) { LayerId = lt[layerName], LinetypeScale = scale };
                circle.SetDatabaseDefaults();//默认参数
                modelSpace.AppendEntity(circle);
                tr.AddNewlyCreatedDBObject(circle, true);
                ext = ext.Add(new Extents2d(circle.Bounds.Value.MinPoint.Convert2D(), circle.Bounds.Value.MaxPoint.Convert2D()));
                tr.Commit();

            }
            //return res;
        }
    }


    public enum ArrowDirection
    {
        East,//东方      右
        West, //西方     左
        North ,// 北方   上
        South, //南方    下
    }

    public enum eDirection
    {
        E_LEFT,
        E_RIGHT,
        E_TOP,
        E_BOTTOM
    }

    public enum eArrow
    {
        E_ARROW_NULL,                   // 无箭头
        E_ARROW_LEFT_ARROW,             // 左边箭头
        E_ARROW_RIGHT_ARROW,            // 左边箭头
        E_ARROW_DOUBLE_SIDE_ARROW,      // 双向箭头
    }
}
